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 position. Additional information about the location such as time zone, currency or country can be determined through geocoding. 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" geographic position with coordinates is returned to the calling application in JSON. Note: A user must explicitly grant permission for an application to access their location.

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 geographic position information about a place or organization by name.

Geolocation Output Parameters

The API queries a Location Information Server, which replies to it 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, through reverse geocoding - E.g. country, city, region, continent, postal code, and whether the country is a member of the EU.
  • Latitude and longitude geohash - Including accuracy, altitude, and speed.
  • Local data, through reverse geocoding -Timezone (including daylight saving time), language (including multiple official languages) and currency (including currency symbol and description) data.

Geolocation API Properties

Geolocation APIs are available for web pages and web-based applications delivered through the Geolocation property which is part of the Navigator object.  Native and richer location APIs are also available for both Android and iOS.

All 3 platforms (web, Android, iOS) will offer 

  • The ability to retrieve the current device location, returned as a latitude, longitude pair along with accuracy, height, altitude, and speed (if known)

  • The ability to watch for changes in position and register a callback to be invoked when the device position changes

Android and iOS will also differentiate between ‘fine’ location and ‘coarse’ location to enhance user privacy and the trade-off between performance and accuracy.  Where application use cases allow, the app should use the feature where a callback is invoked when a user goes near a location (known as ‘visits location service’ on iOS and ‘geofence’ on Android) since this is the most power-efficient API.

Where native or web APIs are not an option, for example when running on an IoT device, there are a myriad of REST location APIs available

Geolocation Use Cases

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 of the United States 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 API mapping alongside this functionality 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.

Related Terms

MORE FROM PUBNUB
Geolocation Tracking Tutorial

Geolocation Tracking Tutorial

In this tutorial you’ll discover how to build a geolocation tracking app that allows users to share locations and send messages in real-time. You will develop a geolocation tracking application that allows participants to locate and interact with each other, based on PubNub's Javascript SDK.
Geolocation Demo

Geolocation Demo

Geolocation connects users around the world empowering them to share information and experiences in real-time from any device. This demo shows how you could use PubNub to share your location

Talk to an expert