Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google API for location, based on user IP address [closed]

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?

like image 699
Ankit Avatar asked Jul 01 '13 10:07

Ankit


People also ask

How does Google get location from IP address?

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.

How do I get Geolocation API?

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).

Is Google Geolocation API free?

The Geolocation API uses a pay-as-you-go pricing model.


2 Answers

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 
like image 70
Peter Knego Avatar answered Sep 19 '22 17:09

Peter Knego


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

like image 45
Jeremy Wadhams Avatar answered Sep 19 '22 17:09

Jeremy Wadhams