22
votes

Does Google offer a RESTful API where I can pass it a city name (or zip) and it returns the longitude & latitude.

I know how to do this with using the Google Maps API, but I really don't want to have my users download the huge 200k Google Maps API solely so that I can geocode a location.

Does anyone know of a URL based (REST) city/zip to longitude & latitude API?

Since geocoding this information then kicks off multiple other processes, doing this first step is of critical importance to have it perform quickly b/c its a bottleneck right now using the Google Maps API b/c of the huge download and JavaScript loadup.

4
As long as I've pointed this out already today - note that you're technically not permitted to use Google's geocoder unless you'll be displaying the data on a Google Map. The same goes for Yahoo. I don't know if they'll actually check on you, though. - Chris B
@ChrisB: This is no longer the case for Yahoo. - Nathan Osman
Actually Yahoo's PlaceFinder license says you cannot store geocoding or other data from the API for future use. - Tomov

4 Answers

5
votes

Yahoo PlaceFinder is a new service offered by Yahoo! that provides services for converting addresses (including city names) into latitude / longitude pairs. The service is also capable of doing the opposite (converting coordinates into an address).

Unlike Google's Geocoding API the TOS for Yahoo PlaceFinder do not forbid using the data outside of their maps API.

4
votes

You could use geonames.org web sevices (or download the server)

http://www.geonames.org/export/reverse-geocoding.html

0
votes

Also keep in mind that you will likely run over your quotas for the day if you have heavy traffic using the direct HTTP call method. Google limits usage based on IP address, so using the client side code will greatly increase the number of geocode lookups you can do per day since they'll be associated with user's computers rather than your server(s).

-2
votes
$.get("http://ipinfo.io", function(response) {
    console.log(response.city, response.country);
}, "jsonp");

Here's a more detailed JSFiddle example that also prints out the full response information, so you can see all of the available details: http://jsfiddle.net/zK5FN/2/