Domanda

What is the most up to date, accurate, turn-key code to inject into a page to automatically read a user's IP and spit out their city... on this page we are borrowing from goingtorain.com I want it to display ... within 3 miles of (dynamic city)

http://www.drillavailable.neighborrow.com/

È stato utile?

Soluzione

Another one we've been looking at to use is http://www.maxmind.com/app/geolitecity. Looks to be fairly simple to setup and is open source/free with apis for most popular languages.

Not done much other than play with it for 5 mins but looks promising.

Altri suggerimenti

I'd go with location aware browsing. Look into the W3C GeoLocation API.

For example, try Google Gears Geolocation module.

These technologies allow your clients to be geolocalized not only by looking and their IP (which can have 200km offsets) but also by triangulating SSID information from nearby wireless Access Points, and this can be extremely precise.

Once you have the (lon,lat) coordinates, it's just a matter of calling some webservice to get the nearest city's name.

I would choose the locator API at http://ipinfodb.com You can access it via XML or JSON, send it your API key and an IP and it will return the city, state, zip, country, etc. You can then parse the results in your language of choice. Its the simplest way to achieve this without actually storing any information about IP/location routing.

Yes, you only need to use the ClientLocation object in the google.loader namespace. In total the whole code is.

<script src="http://www.google.com/jsapi" language="javascript"></script>
<script language="javascript">
if (google.loader.ClientLocation != null) {
  alert(google.loader.ClientLocation.address.city);
} else {
  alert("Not found");
}
</script>

The properties available are

  • google.loader.ClientLocation.latitude
  • google.loader.ClientLocation.longitude
  • google.loader.ClientLocation.address.city
  • google.loader.ClientLocation.address.country
  • google.loader.ClientLocation.address.country_code
  • google.loader.ClientLocation.address.region
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top