Internet‎ > ‎HTML‎ > ‎HTML 5‎ > ‎

HTML5 GeoLocation

The Geolocation API defines a high-level interface to location information associated only with the device hosting the implementation, such as latitude and longitude. The API itself is agnostic of the underlying location information sources. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input. No guarantee is given that the API returns the device's actual location.

The API is designed to enable both "one-shot" position requests and repeated position updates, as well as the ability to explicitly query the cached positions. Location information is represented by latitude and longitude coordinates.

Example of a "one-shot" position request.

function showMap(position) 
    // Show a map centered at (position.coords.latitude, position.coords.longitude).

// One-shot position request.

Example of requesting repeated position updates.

function scrollMap(position) 
    // Scrolls the map so that it is centered at (position.coords.latitude, position.coords.longitude).

// Request repeated updates.
var watchId = navigator.geolocation.watchPosition(scrollMap);
function buttonClickHandler() 
    // Cancel the updates when the user clicks a button.