Geocoding API's Compared

Posted: 2011-02-08

Over the last few weeks I have been doing plenty of work with geolocation and reverse geolocation directly in JavaScript, PHP and Ruby using mostly the Google Map's API. For the majority of map work the Google Map API is fine, but once you go past basic plotting of items on the map, comparing distance, etc and start trying to reverse geocode, everything gets a lot more complicated.

There are several options around but most geocoding or reverse geocoding services are a crusty mess with useless data or no/lacking API's. The best services I could find were Google Maps, Yahoo PlaceFinder and the relatively new SimpleGeo.

Geocoding

One of my recent projects involved writing a custom data management module for a multi-site CMS which could automatically Geocode any addresses when new data is inserted or updated. This would be easy if the system was a single-domain site but unlike the Google  Maps JavaScript v3 API, the PHP API requires an API Key which is registered to a specific URL. This may not be an issue for many of you so we can say that basic geocoding with Google works perfectly, but for me this is a massive fail.

Yahoo PlaceFinder supports an Application ID which is registered to an Application on the Yahoo Developer Network and therefore does not care about the URL. The API looked perfect and really simple to use, but a quick test proved to be inaccurate, as were the majority of the tests I ran after that. As another example, I enter my family house "46" and it returns the details for "28" down the road and the co-ordiantes show the Google Street View of number 5. Not too helpful eh?

This is a common problem in the UK as our main postal service "Royal Mail" is selfish jerk when it comes to allowing people to use it's postcode data. Google were lucky enough to be able to buy a license but as far as I can tell Yahoo never managed to get one. This means simple requests for a house name and road number often end up several houses out and far from accurate, but for many services "somewhere on the road" may be good enough.

While tweeting my complaints about Google and Yahoo I had several people suggest I use SimpleGeo. I'd used it a little before but was under the impression that it had no actual geocoding service. It does but at the time of writing the "address" parameter in the Context API is only for the USA, so thats no good for the rest of us. SimpleGeo right now is mainly about providing you with data about what is at - or near - a specific set of coordinates.

For this project I ended up using Yahoo PlaceFinder through lack of options and luckily the level of accuracy was just about good enough. Google would have been my choice if their API Key was less restrictive.

Reverse Geocoding

Another project I have been working on recently is TravlrApp which uses an awful lot of geocoding and reverse geocoding. If you aren't familiar with the term "reverse geocoding" then it basically means providing human data from a set of Google Map JS Objectscoordinates, so you provide 37.766713, -122.428938 and get 1600 Pennsylvania Ave NW, Washington, DC. Google, Yahoo and SimpleGeo all do this well with varying levels of accuracy but the most important part of reverse geocoding is providing segments of address that your application can understand.

I've been using a City database for TravlrApp to populate auto-complete lists but sadly it the data set seems to be missing some cities. What I wanted to do was let users click the map, have Google tell me the City and Country, have my code check the database and if they don't exist then it should add them to that list. In this day in age I would have thought that would be easy, so I started playing with Google Reverse Geocoding.

Google is very accurate in most countries and is easily the largest data set I have used. Some countries such as Iraq will just tell you that the coordinates are in Iraq, but not many of my TravlrApp customers will be planning holidays there so I am not too fussed. The real problem with using the Google Maps API for reverse geocoding is that the results are returning in a relatively unusable way. For an example of a few of the JS objects returned from the API take a look to the right. This may at first look pretty useful, but the way they return their data is actually about as logical as the average episode of Family Guy... after smoking a whole bowl of meth.

So what is Google doing? Well it will return any number of objects which each have a different level of accuracy. There is no specific number and none of these objects have a specific level, it just gives you as many as it feels like for that specific point on the map. Within each of these objects is an array of "address_compontents" which look more promising (see below).

  Google Address components  

Well that looks pretty useful right? Wrong. Google will give you up to 7 items back with the first being the most accurate and the last being either a postcode, country or sometimes a state. The first could be a house number, street, village or town and there could be any number of entries in-between. This example is the most clean, but sometimes the first line will have the street address mixed in with a postcode and the country name too, and sometimes the city or region will have part of the post code mixed in too. Other parts are often left out or repeated up to 3 times for no obvious reason.

They provide a type property but this is no more useful as everything from a village to a country could be considered "political". Utterly useless.

Yahoo XMLYahoo does a much better job of this by providing a rigid chunk of XML that you can use to pick exactly what piece of information is what. It is still not hugely accurate but if you are clicking on a map you most likely do not need to know the exact address.

First it will take a guess at the line 1 - 4 of your address but more usefully it will tell you exactly what the Street, City, County, State, Country and Postcode along with a few country codes and other useful information. If it is not sure about any of this information it will just leave it blank so you know exactly where you stand when working with this API. In the most populated countries this seems to do a brilliant job but I can't say I have tested it fully. At least in the UK and US it is spot on almost everywhere I query so I may well be using Yahoo PlaceFinder for all my reverse-geocoding needs, even if the geocoding itself sucks.

Finally onto SimpleGeo. I have avoided this in the past mainly because of the Client support. They only officially maintain Objective-C, Android, Java and Python while the .NET, Ruby and PHP ones are left to the community. The PHP client requires a few PECL extensions and I've previously found the Ruby client to lack support for their Places data, but that is another issue altogether. To be fair I cannot complain too much. I was talking to one of the guys behind SimpleGeo and he said "it's open source, fork it!", which I say to lazy and complacent PyroCMS users on a daily basis. Hell, that's why I bought Ed Finklers "Pull Request or STFU" t-shirt!

Client support aside I am wary of using SimpleGeo for reverse geolocation. When using their demo, coordinates in the USA seem to give you a plethora of information but hop the pond to the UK, anywhere in Europe or just anywhere not in the States and you'll be lucky to get much more than "Provincial", "Timezone" and "Country" returned.

Summary

If you are lucky enough to not need to do any multi-domain based work and you do not need Reverse Geocoding then Google will probably do the trick. Google Map API is very accurate, has great data and will not limit you too much as long as you have an API key. That said you can only use Google Geocode data to plot items onto a Google Map. If you do anything else you are violating the terms of use, which is pretty anal if you ask me.

Yahoo provides the easiest access to data as you can geocode both ways with just a file_get_contents() in PHP and as far as I can tell - let me know before their lawyers do - they do not have the same restrictions on where you can use their data. Their accuracy is not always brilliant for geocoding but when the service is free and easy to work with you can't really complain too much.

SimpleGeo clearly has massive potential and I am sure it will only get better in time. For now with it's incomplete data sets, limited official client libraries and use of oAuth for the entire API I can see the average developer having a tough time getting too far with it, but I will keep experimenting with SimpleGeo for TravlrApp as in the USA it seems to work very nicely and has great documentation.

As always my comparison reviews have ended up being "use them all". They all have their pro's and con's and do certain jobs well. It's just a shame SimpleGeo does not do it all perfectly - yet.

Comments

Gravatar
London Web Development

2011-02-09

good info, i am also making a tiny app with geo locartion feature along with CI

Gravatar
Joel

2011-02-09

I thought v3 of the google maps API didn't require an API key?

Gravatar

2011-02-09


Joel: v3 of the JavaScript API does not need a key but you try finding a PHP solution that does not need a key. You can use the Geocoding API which is technically different but that is the one littered with all the "use this for anything other than plotting markers on a map and we'll kill your family" messages.

Gravatar
Peter

2011-02-09

how abou gisgraphy or geonames? have you tried those?

Gravatar
Baczek

2011-02-09

you could throw together a solution for v3 api in the time it took you writing this post. it's just a HTTP GET json request.

Gravatar
Dale

2011-02-09

Check out , sounds like Yahoo! may be applying similar terms of service, in particular "you can only use our geocodes on our maps and don't ever store the geocodes." This would be in line with terms for their previous geocoding API, as well as most other providers who generally claim that the (very few) upstream sources for this data require these terms.

Gravatar
Dale

2011-02-09

Agh, link lost in last comment: http://developer.yahoo.net/forum/?showtopic=6350&endsession=1

Gravatar
Gerald Farmer

2011-02-10

I really like AlwynGeocoder. Very fast and stable.

Gravatar

2011-02-10

Baczek: Not legally I couldn't. As I said in the post, Google Geocode data has to go on Google Maps.

Dale: Great, so that's another service that is essentially useless. SimpleGeo it is.

Peter: Those services demand very specific input criteria, you can't give it a human address and have it parsed like Google and Yahoo will do. You need to specify "Post code" etc. Besides I do not trust Geonames as they are the provider of the awful City database I referenced when talking about Travlr.

It just seems that if A) you live in the UK or B) you aren't plotting data directly onto a map by the same provider, you really do need to pay for decent geolocation. :-/

Gravatar
Doug

2011-02-27

Dale, Phil: About Yahoo! PlaceFinder and whether it can be use for profit.

The full terms of use are annoyingly spread over 3 URLs. To avoid confusion, the Terms of Use I'm talking about are available from the bottom of http://developer.yahoo.com/geo/placefinder/ and currently link to:

1. APIs Terms of Use: http://info.yahoo.com/legal/us/yahoo/api/api-2140.html

I can't see any condition on that page that says you can't use it for profit. (Section 1.g.iv is to do with commercial reselling of the service, so not relevant)

The PlaceFinder API is not governed by an API-specific set of terms, which are listed at the bottom as:

Yahoo! Maps API Terms of Use
Yahoo! Messenger IM API Terms of Use
Yahoo! Music API Terms of Use
Yahoo! BOSS Search APIs
Yahoo! Address Book API
Yahoo! Search BOSS Services
Yahoo! Web Analytics APIs
Yahoo! Fantasy Sports APIs

Finally, two additional sets of terms are applicable - the Terms of Service and Guidelines - and these are linked at the top:

2. Terms of Service: http://info.yahoo.com/legal/us/yahoo/utos/utos-173.html

This forbids commercial resellers, so again not relevant. No other mention of commercial use.

3. Guidelines: http://info.yahoo.com/guidelines/us/yahoo/ydn/ydn-3955.html

This says "Some of our APIs and Web Services are made available only for non-commercial use." and goes on to place some restrictions on those - but the PlaceFinder API is not one of them.

It does also place tight restrictions on the Maps API, but Eddie Babcock of
Yahoo! Geo Technologies makes it clear that "Use of PlaceFinder does not require the use of Yahoo! Maps or Yahoo! Maps APIs." (from Dale's link to http://developer.yahoo.net/forum/?showtopic=6350&cookiecheckonly=1#post-main-22528)

So unless I've got this badly wrong, Yahoo! PlaceFinder is fine for commercial use.

Gravatar
Maler München

2011-07-22

Currently i have a problem with the Yahoo! Placefinder API. I wonder how i can change the accuracy.

Gravatar
Nafg

2011-08-02

Have you seen geocoder.ca? (Only for US and Canada.)

Gravatar
Roynwaqqzi

2012-03-06

Christian Louboutin shoes are classics and can be worn for a long time. <a href="http://www.lrechristianlouboutin.com/">Christian Louboutin Sandals</a> They are sexy in addition to comfortable. Chirstian Louboutin Shoes - http://www.lrechristianlouboutin.com/ I have been lucky enough to own one pair i have <a title="Chirstian Louboutin Shoes" href="http://www.lrechristianlouboutin.com/">Chirstian Louboutin Shoes</a> worn for days gone by 8 years.What makes you <a href="http://www.lrechristianlouboutin.com/">Chirstian Louboutin Shoes</a> think they can only be worn once?Payless shoes <a >Christian Louboutin Pumps</a> on the opposite hand won't last more than a season if worn a whole lot.How to choose Christian louboutin sandals online to provide more comfort.On One Hand: Depends on Your Legs and Style.Many women say Christian louboutin 2011 spring shoes would be the most comfortable heels they've already ever worn.However,whether or not this can be true for you really depends upon the shape of your own foot.There is no one "right" shoe for you.Each designer has a different arch configuration that can greatly impact how comfortable heels are for you.Furthermore,the style of the shoe you decide will affect how at ease your Louboutins are for you.They're not all the identical,so you're just have to to try them available.On the Other: Louboutins Are Among the most effective.Although it can't end up being said definitively that Christian Louboutin reviews shall be comfortable for you,it's true that these shoes rank one of the most comfortable heels again along with again.Christian Louboutin's most remarkable trait could be the lathy heel、red and lacquer lone,it is the designer's trademark.The Louboutin's trademark glossy red soles give an instantaneous stamp of fashion excellence.The designer's ethos is to "make shoes that are usually like jewels" and every unique design demonstrates unmatched quality and an natural sultriness.From vertigo-inducing pumps for the seasonal must-have shoe boots in addition to a covetable range of hand bags and clutches,Christian Louboutin is the accessories brand for every super-chic fashionista.The red sole,the recognition is and so high,and the Christian Louboutin sale is well.All women are crazy to obtain louboutin sale for one pair "red sole" hindfoot shoes.Man's line of picture,woman's desire,let Christian louboutin shoes and boots are famous of 19 years standing,So many Hollywood's Legend loves the Christian Louboutin shoes,and they are the free prolocutor to the louboutin.Only see the reddish sole,don't find the brand,people will know Christian Louboutin. long year acer trends show only 001 more acelenolysunci topics now pr41 in 2012

Gravatar
Click

2012-07-02

Your means of telling the whole thing in this
paragraph is actually good, all can simply be aware of it,
Thanks a lot.

Gravatar
Geocoder

2012-11-24

I acctually just started a new Geocoding service myself.

It cost me over 12m dollars in just licensing fees to get the data and another 3m in getting the data formatted properly for my database. My servers alone cost me 4000 per month.

If only these companies didn't have such limitations.... GRR.

Another thing that I did was partner with a few other geocoding providers to use thier data (3 currently) and in exchange for using their data and storing it, I let them geocode through my data if theirs fails. Kinda like a trade, if mine fails, uses them, if theirs fails, uses me. :)

Posting comments after three months has been disabled.