Geolocation and Google MAP API Quick Guid

Geolocation API

Geolocation API is used by a Web browser to get the location information of the user, which is critical in the development of a location-aware Web application. Geolocation object is a property of navigator object. It supports the following three method calls:

position object includes the following properties:

positionError object includes the following properties:

positionOptions object argument for getCurrentPosition()/watchPosition() includes the following properties:

An example is given below to see how to use Geolocation API:

        navigator.geolocation.getCurrentPosition(function(position) {
          // do whatever with position.coords.longtitude and position.coords.latitude
          ...
          }, function(error) {
          // do whatever with error object
          ...
          });
      

Google Maps API Guide

To include a Google MAP in the Webpage, follow the following steps:

  1. Obtain an API key at the APIs Console with a Google account;
  2. Include Google Maps API in the Webpage: <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE"> </script>. Replace YOUR_API_KEY with your API key, and SET_TO_TRUE_OR_FALSE to true or false on using a sensor (like a GPS chip);
  3. Include an empty div section in the Webpage with size spcified. Suppsoe its id is "map";
  4. Specify the map's options in a MapOptions object, such as the center coodinates of the map, zoom level, map type, etc.;
  5. Load the map: var map = new google.maps.Map(document.getElementById("map"), mapOptions);

References

  1. Geolocation API Specification
  2. Using geolocation
  3. Google Maps JavaScript API v3
  4. Anthony T. Holdener III, HTML5 Geolocation