I am looking for a way to get the user's current location (city) based on is IP address using the Google Maps APIs.
Something similar to http://freegeoip.net/json but only using the Google Maps APIs. Is this possible?
The location used and stored with your Web & App Activity can come from signals such as the device's IP address, your past activity or from your device, if you've chosen to turn on your device's location settings.
The Geolocation API is accessed via a call to navigator. geolocation ; this will cause the user's browser to ask them for permission to access their location data. If they accept, then the browser will use the best available functionality on the device to access this information (for example, GPS).
The Geolocation API uses a pay-as-you-go pricing model.
Google already appends location data to all requests coming into GAE (see Request Header documentation for go, java, php and python). You should be interested X-AppEngine-Country
, X-AppEngine-Region
, X-AppEngine-City
and X-AppEngine-CityLatLong
headers.
An example looks like this:
X-AppEngine-Country:US X-AppEngine-Region:ca X-AppEngine-City:norwalk X-AppEngine-CityLatLong:33.902237,-118.081733
It looks like Google actively frowns on using IP-to-location mapping:
https://developers.google.com/maps/articles/geolocation?hl=en
That article encourages using the W3C geolocation API. I was a little skeptical, but it looks like almost every major browser already supports the geolocation API:
http://caniuse.com/geolocation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With