views:

100

answers:

2

I am using Google Map's ClientLocation to retrieve the users geolocation (via their IP address). This is very slow because you first have to download and then load Google Maps, before it can even begin to geolocate the users IP address.

Then I came across http://fwix.com/. They are doing exactly what I want, but super fast without having to use Google Maps ClientLocation.

It appears they are generating the HTML page on the fly and injecting the latitude and longitude into the META area of the HTML.

Just view the source for fwix.com and you'll see something like:

<meta name="geo_lat" content="12.34567" /> 
<meta name="geo_lng" content="-98.76543" /> 

Questions:

  1. How does fwix doing this?
  2. What is the quickest way for me to retrieve a users geolocation (lat/lng) without having to load the entire Google Maps API? Meaning, if there a web service I can call programically that will simply return the users geolocation (lat/lng)?
+2  A: 

You don't need any interaction from the client (besides their initial request, which reveals their IP address to the server) to locate them by their IP address.

Geolocation via IP is all done on the server side, and this can be quickly relayed to the client. If you experience slow loading, that's because your browser is loading something else.

NullUserException
I might add that the IP is a very unreliable method of finding one's location. Usually within 10-50 miles is the pattern, at least in Los Angeles.
Novikov
@Novikov That's pretty good.
NullUserException
@user401 You'll need an API that can do that for you. See http://www.maxmind.com/app/ip-location for example
NullUserException
+1  A: 

It depends on your need, if you are only interested to get your visitors geolocation without the hassle of owning the data in your server, the easiest option may be to use a free web service like IP2Location Web Service from FraudLabs.com. They have the full version and free license as well.

JaceyKala