views:

86

answers:

3

Does anyone know of any open RESTful API that I can call to geocode a user's IP to the latitude and longitude?

Ideally, it would be something like: http://google.com/geocode_api/?IP=1.2.3.4 and it would return the latitude and longtitude.

A: 

You could use the google API: http://code.google.com/apis/ajax/documentation/#ClientLocation

Edit

Example:

<script type="text/javascript"
    src="http://www.google.com/jsapi?key=ABCDEFG"&gt;&lt;/script&gt;
<script type="text/javascript">
google.load("maps", "2.x", {callback: initialize});

function initialize() {
  if (google.loader.ClientLocation) {
      var lat = google.loader.ClientLocation.latitude;
      var long = google.loader.ClientLocation.longitude;
      alert ("lat: " + lat + "\nlong: " + long);
   }
   else { alert ("not available"); }
 }

Josiah
Can I use that without loading the entire Google Map framework? Reading the docs, it's unclear to me what module google.loader.ClientLocation exists within
Tim
It doesn't exist within any of the API modules, it's a part of the API loader framework. It's a sister command to google.load .
Josiah
So how can I load JUST ClientLocation without any other modules?
Tim
I've added example code. But it looks like you actually have to load a module to populate ClientLocation. You could load the search API instead which is relatively small and probably already exists within a user's cache.To load the search api change "maps" to "search" and "2.x" to "1"
Josiah
+1  A: 

Here's a couple with simple calls...

Example calls :-

Example of returned XML (ipinfodb) :-

<Response> 
  <Ip>122.169.8.137</Ip> 
  <Status>OK</Status> 
  <CountryCode>IN</CountryCode> 
  <CountryName>India</CountryName> 
  <RegionCode>10</RegionCode> 
  <RegionName>Haryana</RegionName> 
  <City>Kaul</City> 
  <ZipPostalCode></ZipPostalCode> 
  <Latitude>29.85</Latitude> 
  <Longitude>76.6667</Longitude> 
  <Timezone>0</Timezone> 
  <Gmtoffset>0</Gmtoffset> 
  <Dstoffset>0</Dstoffset> 
</Response> 
Andy Robinson
A: 

Hi, if you are looking for real time tracking then you can try XML web service. Try this (http://www.fraudlabs.com/ip2location.aspx) and get their free license key for your lookups. They provide 90 free queries every month. :)

SuperRomia