Robin Barnes
Robin Barnes

Reputation: 13541

Generate google map based on UK postcode

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?

Upvotes: 6

Views: 19756

Answers (9)

faye
faye

Reputation: 105

Small UK business or charity can apply for a free licence of use PAF. https://www.poweredbypaf.com/register-for-free-use-of-paf/

Upvotes: 0

dbramley
dbramley

Reputation: 111

What about using:

<img src="http://maps.google.com/maps/api/staticmap?center=POSTCODEHERE&zoom=14&size=200x200&maptype=roadmap&markers=color:ORANGE|label:A|POSTCODEHERE&sensor=false" style="float: right">

Then replace POSTCODEHERE in the two sections above with their postcode.

You can change the size from 200x200 or the marker colour, label etc. too if you wish.

Upvotes: 11

Oli
Oli

Reputation: 239810

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.

Upvotes: 3

Bobby Jack
Bobby Jack

Reputation: 16018

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?

Upvotes: 1

Shadi Almosri
Shadi Almosri

Reputation: 11989

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.

Upvotes: 0

jheriko
jheriko

Reputation: 3113

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..

Upvotes: -1

Ben Aston
Ben Aston

Reputation: 55729

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.

Upvotes: 1

frankodwyer
frankodwyer

Reputation: 14048

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/

Upvotes: 0

gbjbaanb
gbjbaanb

Reputation: 52659

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.

Upvotes: 0

Related Questions