views:

2380

answers:

7

Hi,

Is it possible to do a google map lookup using the google maps API from a UK postcode? I know you can search by UK postcode on their website, but this converts to lat / long. I don't have access to the PAF database to be able to convert to long / lat.

An example:

Users have an item to sell. One of the details of that item is a postcode, where the user / item is located. When the items are displayed on the front end of the website, there needs to be a google map of the items location generated using the postcode.

If this is possible, how do I do it.

Thanks

A: 

you need the PAF database, each postcode is held as a polygon, so unless you have that initial data you cannot restrict the search to the polygon, or to a radius around the centrepoint.

The postoffice will sell you all the data you require though, prices start from £85pa.

PS. Google does it because they have the PAF database, when you type in the postcode, they lookup the centre and display that on their map.

gbjbaanb
Yeah this is pretty much what I thought the deal was. Really only £85 for PAF? At one company I worked for they charged us like £5k for it.
"start" at £85, for a single user. For a website, it's £3850, but you do get everything, not just postcodes.
gbjbaanb
A: 

The folks behind openstreetmap.org have been working on a free equivalent - I don't know how ready for prime time it is, but FWIW:

http://freethepostcode.org/

frankodwyer
A: 

Google does not provide a geocoding api in the UK because of the licensing model the Royal Mail releases postcode data under.

The are however some tools that people have written that enable geocoding using google, but that would be technically illegal afaik.

One option then is to use one of the several uk geocoding providers. I don't want to sound lazy but they are easily googled. They typically charge a few pence per geocode.

Ben Aston
+2  A: 

The accepted answer is incorrect.

You can do it purely though Google maps.

I did it for a client earlier this year and have just had to do a few modifications. I also did some direction-grabbing. It's all pretty simple but best viewed in context.

Take a look at the source of the page I made.

Oli
Your site seems to automate google, not quite what the OP asked for, but quite possibly what he wants.
gbjbaanb
Have you looked into the legality of this approach though? (as mentioned in my answer)
Ben Aston
Re both: It's all using their public API. It's not the best documented of features, but it's not like I'm screen scraping! I am doing more than the OP is asking for because I'm hooking into LocalSearch for directions, but the whole geo-coding thing is possible.
Oli
Hi, I had a look at the js source for the page you made and rexamined the google api. It looks like you're right. Going to try to implement it all tomorrow. Thanks a lot. And yes - your solution seems perfectly legal as part of google's api allows for an api call based search.
+1  A: 

No one seems to have searched very hard... there is a freely available list of UK postcodes and positions out there. More importantly its all redundant because Google maps provides the ability to search by post code to begin with. Even using the API is a redundant extra given that the service is provided over the internet... there is nothing to stop you sending a http request yourself and displaying portions of the returned data, as long as you preserve any necessary copyright messages etc..

jheriko
A: 

http://www.websemantics.co.uk/resources/postcode_to_coordinates_conversion_tool/

Site will provide you with a longitude and latitude which you can place right into your google code.

Shadi Almosri
+1  A: 

It's (now) very easy to do this using google's LocalSearch API:

function usePointFromPostcode(postcode, callbackFunction) {
    localSearch.setSearchCompleteCallback(null, function() {
        if (localSearch.results[0]) {
            var resultLat = localSearch.results[0].lat;
            var resultLng = localSearch.results[0].lng;
            var point = new GLatLng(resultLat,resultLng);
            callbackFunction(point);
        } else {
            alert("Postcode not found!");
        }
    });

    localSearch.execute(postcode + ", UK");
}

callbackFunction() will receive a GLatLng object with, in my experience, very accurate coordinates. In fact, it's trivial to then feed that GLatLng to a GClientGeoCoder's getLocations() method and get back full Placemark details, which include details down to the level of address range (e.g. 1-18 Foo Street).

The real question is: how legal is that?

Bobby Jack