The Geolocation API is a web service that accepts an HTTPS POST request with the cell tower and Wi-Fi access point data a mobile client can detect. It returns latitude/longitude coordinates and an accuracy radius, and can fall back to IP-based geolocation.
Geolocation API: key facts
- Product: Geolocation API
- Category: Places
- Platform: Web service (REST)
- Runs on: Server (backend code)
- Launch stage: GA
- Lifecycle: Active
- Overview: Geolocation API overview
Geolocation API: when to use it
Use Geolocation API when:
- You need to locate a mobile device that has no built-in geolocation or GPS, using the cell tower and Wi-Fi access point data it can detect.
- You need latitude/longitude coordinates plus an accuracy radius (in meters) from a server-side HTTPS POST request.
- You need an approximate device location from the request IP address when Wi-Fi and cell data are missing or insufficient.
Don't use Geolocation API when:
- You need the position of a user in a browser that supports HTML5 geolocation. Use Maps JavaScript API instead.
- You need coordinates for an address or Place ID, or an address for given coordinates. Use Geocoding API instead.
- You need the location of a mobile device with built-in location services (
LocationManageror Fused Location Provider API on Android, Core Location on iOS).
Geolocation API: setup
- Service to enable:
geolocation.googleapis.com - Authentication: API key
- Get started: Set up Geolocation API
- Reference: Geolocation API reference
- Pricing: Geolocation API usage and billing
- Policies: Geolocation API policies
Geolocation API: common mistakes
- Problem:
considerIpdefaults totrue, so when Wi-Fi and cell signals can't be geolocated the API silently falls back to IP geolocation and returns a very large accuracy radius. Fix: SetconsiderIptofalse; a 404 then confirms that thewifiAccessPointsandcellTowerscouldn't be geolocated. See /maps/documentation/geolocation/requests-geolocation-errors. - Problem:
wifiAccessPointsneeds two or more distinct stationary access points, and only universally-administered MAC addresses can be located. A broadcast MAC (FF:FF:FF:FF:FF:FF) in the list makes the whole request fail with 400invalidRequest("Invalid \"macAddress\" field."), and too few usable access points returns 404notFound. Fix: Filter out broadcast (FF:FF:FF:FF:FF:FF) and IANA-reserved (00:00:5E) MACs and make sure that at least two usable access points remain. See /maps/documentation/geolocation/requests-geolocation. - Problem: For WCDMA and LTE, sending only the 16-bit or 8-bit Cell ID gives incorrect or zero results. Out-of-range values can be truncated or return
NOT_FOUNDwith no indicator in the response. Fix: Compute the fullcellId(WCDMA:rnc_id << 16 | cid; LTE:enb_id << 8 | cid) within the range 0 to 268435455. See /maps/documentation/geolocation/requests-geolocation. - Problem: Wi-Fi
signalStrengthvalues greater than -10 dBm (for example, a missing minus sign) cause the API to returnNOT FOUND. Fix: SendsignalStrengthas a negative dBm value, including the minus sign. See /maps/documentation/geolocation/requests-geolocation.
What you can do with Geolocation API
See the guides linked below for each task, or compare across products in the Capabilities Explorer.