11

What is the most complete, precise and reliable way to get the coordinates (latitude / longitude) of a given ZIP / Postal Code of a given country? I need to make a lot of requests, so a high API limit rate (maybe even absent) would be useful.

GeoNames dumps would be cool, but it seems to have way too many duplicate coordinates (example) and it also seems that their database is missing some ZIP / postal codes for specific countries.

Are there any other (reliable) alternatives?


While I was reading a Meta question, I came across this link:

http://query.yahooapis.com/v1/public/yql?q=select%20%2A%20from%20geo.places%20where%20text%3D%22Jyv%C3%A4skyl%C3%A4%22&format=xml

I had heard of the YQL before but I had no idea I could use it to GeoCode addresses, so I searched a little and I found this very interesting piece of information:

Usage Limits

Per application limit (identified by your Access Key): 100,000 calls per day

Per IP limits: /v1/public/: 1,000 calls per hour; /v1/yql/: 10,000 calls per hour

Does anyone know where I can get more specific info in using YQL to GeoCode addresses?

Community
  • 1
  • 1
Alix Axel
  • 141,486
  • 84
  • 375
  • 483
  • Many dupes including http://stackoverflow.com/questions/1320262/web-service-to-get-the-gps-coordinates –  Jan 16 '10 at 13:27
  • @Neil: Not exactly, all the answers in that question use the GYM / GYB APIs and have low rate limits. – Alix Axel Jan 16 '10 at 15:41
  • 1
    Would you care to explain more closely what you need the data for? In Germany, for example, a single post code applies to a very large zone, defined by district or county borders. Two addresses with the same 5-digit post code can be as far as 10-20 km apart. The same is the case in my native Finland (with even greater distances). A geocode on a post code can this only be an imaginary center point. You seem to pay great attention to the quality of the data - how will that work for you? Also, does the operation really need to take place in one day? Why not distribute queries over a few weeks? – Pekka Jan 16 '10 at 21:28
  • @Pekka: Yeah, in my country (Portugal) we have 7 digit postal codes, each postal code is less than 1km away from the next one. I'm aware that not all countries share the same level of precision (unfortunately) but I'll have to level with that. The postal office in Portugal want nearly 33k€ for 80% postal code coverage of the country (and they don't even use the WGS84 standard). I cannot share the specifics of the project, but I need to geocode each postal code in Europe in a rather short period of time (2 to 3 weeks), I got Portugal nearly done but there are still 26 countries to go... – Alix Axel Jan 16 '10 at 21:45
  • I'll put it into an answer, see below. – Pekka Jan 16 '10 at 22:03
  • @Pekka: Also, one of the problems I face is to get a (up to date) list of all the existing postal codes, since without that I cannot geocode anything. Wikipedia for instance (http://en.wikipedia.org/wiki/List_of_postal_codes_in_Portugal) only has a list of the first 4 digit postal codes - which means I've to issue 1000 brute-force requests (999-000) for each one. – Alix Axel Jan 16 '10 at 22:04
  • I don't know for sure (And for Portugal you know better than I do), but I would think getting lists of the raw postal codes (without coordinates) from the national post offices should be possible. Maybe worth a second SO question? – Pekka Jan 16 '10 at 22:15
  • Plus, Brute-Forcing won't work in the UK and Ireland, at least... – Pekka Jan 16 '10 at 22:16
  • @Pekka: Yeah, their postal codes are really neat! I've already done some research on that, only a few post offices provide raw lists of postal codes, others do but pose a lot of restrictions. Luckily I think that Portugal is one of the countries with the most postal codes. – Alix Axel Jan 16 '10 at 22:18
  • All right. Well at any rate, I'd be interested to learn how it turns out in the end! As I said below, if you have some budget, your best bet is probably talking to Google & co. On the other hand, their quality cannot be blindly trusted either - that's where the post offices would probably be more reliable. Anyway, good luck! – Pekka Jan 16 '10 at 22:22

4 Answers4

6

Yahoo! GeoPlanet will give you centroid lat/long points for postal codes. They've been reliable in my experience. The API limit is 50,000 requests per day. I'm not sure what their policy on caching results is. I get the impression that if you contact Yahoo!, you can set up an arrangement with a higher request limit, though it may cost some money.

They also let you download a substantial portion of their data under a Creative Commons license, but unfortunately that appears to be limited to the WOEID relationships and country names.

npdoty
  • 4,498
  • 22
  • 24
  • Thanks, but still 50k requests a day is still not enough for me (my small country alone has almost 300k postal codes). Also I've found that Yahoo isn't very precise in postal codes to coordinates, the same coordinate is returned for several different postal codes. Nice to know about the WOEID dump, though. =) – Alix Axel Jan 16 '10 at 21:19
  • Good to know your experience with their imprecision. I agree with Pekka above; it might cost some money, but try asking Yahoo! and maybe for a small fee you can get them either to lift the daily limit or work something out where you can cache the results. – npdoty Jan 19 '10 at 00:28
5

I think that your choice will probably depend on how many API call you intend to make per day. The daily limit of the free Google Maps API is 15,000 request per IP address. (Source: Google Maps API FAQ.)

You can do geocoding with Google Maps API using the following HTTP request:

Simple CSV:

http://maps.google.com/maps/geo?q=W1A+1AA,+London&output=csv&sensor=false

More Complex XML:

http://maps.google.com/maps/geo?q=W1A+1AA,+London&output=xml&sensor=false

Simply change the "q" parameter with the postcode and country to geocode.

However, I think that storing the geocoding results permanently in your database may be a violation of the Google Maps API terms and conditions. You may want to check for more information about these restrictions.

Daniel Vassallo
  • 312,534
  • 70
  • 486
  • 432
  • 15,000 a day it's kinda low for what I want... BTW what does `sensor=false` do? – Alix Axel Jan 16 '10 at 13:33
  • Google can increase your geocoding limits for about $10k per year: http://groups.google.com/group/Google-Maps-API/browse_thread/thread/1b416f54040b87aa. You didn't say it has to be free :) – Daniel Vassallo Jan 16 '10 at 13:40
  • high API rate = geocode all zip / postal codes for a country in one day – Alix Axel Jan 16 '10 at 13:40
  • 2
    That would exclude Google Maps, and probably any other web-service. In addition, I think that storing the geocoding results permanently is a violation of the Google Maps terms. – Daniel Vassallo Jan 16 '10 at 13:46
  • but you could use memcached to not waste api calls ;-D – jacktrade Mar 20 '12 at 13:42
2

The easiest way would of course be finding a high-quality service provider with no request limit. Why not ask Google for an offer? From what I hear, they are quite flexible towards business customers.

If that's not an option, you will certainly be able to get individual data files, and fare cheaper than 33 grand in many countries. I'm quite sure German and Austrian sell data files at 3-figure prices, and for the UK there's the Postcode Address File (PAF) it's data from the Royal Mail, I don't think quality gets better than that. Of course, in addition to the cost and hassle, there would be a lot of converting work to do with 26 individual files from different Post offices and whatnot - work I wouldn't envy anybody for :) If you have the budget, it's probably cheapest to talk to Google or Yahoo.

Pekka
  • 418,526
  • 129
  • 929
  • 1,058
  • UK: They make updates to their postal codes almost every week! I found a relatively cheap data provider (http://www.geopostcodes.com/buy_eu_zip_codes) but I'm not very sure about the quality of their data. – Alix Axel Jan 16 '10 at 22:14
  • Interesting, I didn't know that, but they are almost down to a house in the UK, so it's obvious they fluctuate a lot... Well, that explains why the annual subscription with Royal Mail costs £1700 :) – Pekka Jan 16 '10 at 22:18
  • Still I think it's an abuse, here we have street level precision and they only make changes to postal codes once or twice in a year. – Alix Axel Jan 16 '10 at 22:20
  • 1
    Yup, I've made the same experience with Google's data over here at home, a big part of my district is not geocoded to street level (and that in a major city!) – Pekka Jan 16 '10 at 22:28
  • 1
    And yes, £1700/year is a rip-off, no question. As is 33k, or any fee at all - after all, this is public data paid for with taxes in most (if not all) european countries. – Pekka Jan 16 '10 at 22:30
1

That's actually a really tough problem since a ZIP code is not actually a polygonal region, but a set of lines aggregated together (see the best anser to How to get the bounding coordinates for a US postal(zip) code? for a very detailed explanation of this.)

Within the United States, the Census Bureau maintains a list of approximate Zip Code boundaries called the "Five digit Zip Code Tabulation Areas" (ZCTA5). You can download these directly and process them however you like. There are several geocoding tools which can get you started with this; I use PostGIS (http://postgis.net/) but there are others, most importantly the Open Street Maps data (http://www.openstreetmap.org), which covers the world.

JWLM
  • 432
  • 2
  • 10
  • very simple API for US boundaries. www.boundares-io.com , it does cost money($25 bucks a month to hit the API) ***Disclaimer i work for them*** – Jeryl Cook Jan 15 '17 at 05:58