A client-side geolocation service which using Google's services.

When to use it?

If you need geolocation data in your client applications and you are targeting browsers where the geolocation API is not available (see canisue.com for a quick overview of its availability).

IP geolocation can give false results if the user is coming through a proxy / VPN / NAT service - in this case it will "locate" the exit point. Don't take the results of the API as absolute proof about the user's location!

If you have a list of IPs for which you need to retrieve their approximate physical location, use something like the MaxMind GeoIP database which is also available in a free version. Just remember that IP blocks get reassigned all the time so you should get a version of the database "close" (in time) to when those IPs were collected.

Caveat emptor!

This is a free service and while I'm happy to provide some small funding to it, if you use it commercially, please support me through PayPal or Flattr:

How to use it?

Call the following endpoints (using jQuery.ajax or equivalent mechanisms):

This gives the geolocation for caller's (external) IP in the following format:

{ "city":"cluj-napoca", "cityLatLong":{ "lat":46.777248, "long":23.59989 }, "country":"RO", "region":"cj" }

There is also an API to return the caller's external IP:

This returns:

{ "ip":"128.96.11.38" }

In addition to JSON the service also supports JSONP. To use it specify ?format=jsonp&callback=callback_name (callback name can contain uppercase and lowercase letters and numbers). For example https://eu-js-geolocation.appspot.com/api/ip?format=jsonp&callback=test will reply with something like:

test({"ip":"128.96.11.38"});

The application has two instances deployed and depending where you anticipate most of your visitors coming from you should either use:

The US instance: https://us-js-geolocation.appspot.com

The EU instance: https://eu-js-geolocation.appspot.com

More technical details