What is a Geolocation API?
A Geolocation API is a communication interface between a client device or application (client-side), and an application or service (server-side) that identifies and returns information about the client’s geographical location. The output parameters may include details about the currency used at that location, the time zone and even whether the country is a member of the EU.
It is called when there is a need to programmatically configure a web or mobile application based on the user's location and common use cases include real-time map navigation and geotracking, serving contextual advertisements, implementing user security checks, and tailoring content to certain regions.
The Geolocation API does not store any information in itself, but rather provides the ability to gather existing information from the device being queried. It can collect location info from sources such as IP Address, GPS, WiFi, Bluetooth, RFID, GSM/CDMA ID, or user input. Once an API query is completed, a "best-guess" location with coordinates is returned to the calling application in JSON.
Note: A user must explicitly confirm permission for an application to use their location information. However, when a browser uses your location (as allowed in engine’s settings), it does not necessarily tell you that it is doing so. Mozilla Firefox is remedying this.
How Does a Geolocation API Work?
Geolocation Input Parameters
Typically, a request for location information to a Geolocation IP is from a device, e.g. a computer or mobile phone, which provides one or more of the following input parameters: an IP address, MAC address, RFID, GPS coordinates, cell tower (e.g. GSM, WCDMA or CDMA) ID or WiFi position. A user can also request location information about a place or organization by name.
Geolocation Output Parameters
The Geolocation API queries a Location Information Server, which replies to the API with various location properties, including the accuracy of the information it is passing on. The API then returns this information to the client. Where the information comes from is transparent to the API and the API does not itself store any data.
The information a typical Geolocation API provides varies but may include the following:
- Physical address - E.g. country, city, region, continent, postal code, latitude and longitude, and whether the country is a member of the EU.
- IP address and ISP details - Including information about whether the IP is a proxy address.
- Carrier - Mobile carrier name, area code and network code.
- Local data -Timezone (including daylight saving time), language (including multiple official languages) and currency (including currency symbol and description) data.
- Threat information - Whether the IP address has been a source of malicious activity.
Geolocation API Properties
The Geolocation API can be accessed with the Geolocation property as part of the Navigator object. The Geolocation property includes a set of three methods, namely:
- getCurrentPosition() – Retrieves the device location data and stores the coordinates (latitude + longitude), altitude (if available), and accuracy in a Position object which can be used in a callback function. Second and third optional arguments can be set to specify: 1) an error callback and, 2) the desired level of accuracy, the timeout value, and the maximum age to cache position data.
- watchPosition() – Starts a watch operation which adds the current position to a Position object, and polls the device for system events that indicate any changes in location. When new location data is available, the Position object is updated to reflect the new position. As in getCurrentPosition(), one can optionally set an error callback and extra options (accuracy, timeout, and max age).
- clearWatch() – Stops an ongoing watch operation specified by the operation's WatchID. WatchIDs are originally assigned to a watch operation when calling the watchPosition() method.
All major web browsers (Firefox, Chrome, Safari, Opera) support the Geolocation API and it is in extensive use on mobile devices such as Android, iOS, Windows Phone, and Maemo.
Geolocation API Use Cases
From matching people looking for romance with like-minded souls in their area to enabling businesses to track their customers, geolocation is used primarily to geographically customize a user’s digital experience.
- Browser Context - When you are searching the internet, your browser may want to query your location in order to provide locale-specific information that is relevant to your query, e.g. businesses located in your area or local news.
- Weather Reports - If you want to check the weather on your phone, the device will need Location set to ON in the phone’s Settings.
- Social Media Updates - Applications like Facebook use location APIs so users can tag their locations in their status updates, e.g. show their friends where they are vacationing.
- Employment and Business Networking – Job searching websites use geolocation to match job searchers with opportunities available in their area.
- Digital Maps - Lost in a strange city? Use your phone to pinpoint your location and find the fastest route to your hotel using Google Maps.
- Marketing and Customer Engagement - Web applications use a Geolocation API to monitor a user’s position when they’re out and about town. For instance, when a person goes shopping, an application may alert them to current specials in a particular store or suggest restaurants in the area based on a user’s previously discerned culinary preferences.
- Tracking IoT Devices - Smart home devices or wearables, and vehicles can easily be tracked or located with geolocation.
- Cybersecurity - Geolocation can be used to track network intruders or suspicious system logins; identify when and where fishy online transactions are made; and discover the shady organization behind an IP address.