views:

339

answers:

3

This is for a search facility on a website. I have it all working using the standard Google Maps geocoder, but for some strange reason it seems to search only on the first part of a postcode.

It can be done in client-side JS using GlocalSearch. However, it isn't clear how to translate this into a server-side solution.

Here is a simplified version of what I have at the moment:

<?php
$requestURL = "http://maps.google.co.uk/maps/geo?output=csv&amp;key=$apiKey&amp;gl=uk&amp;q="
  . urlencode($_GET['pc']);
echo file_get_contents($requestURL);
?>

(Put your API key in to test.) Try, for example, DE1 2PQ and DE1 3NF. Exact same coordinates reported for both.

Any ideas?

A: 

The UK mapping data is expensive, it's possible that Google only have a licence to the higher level postcode data for the first part of the code (the overall area) and not the full street level position.

edit:
Or they might have a non-distributable licence to the exact data. But the large scale data is freely available.

And why you should have to pay the public owned post office for public data that would make their job easier is even less clear.

Martin Beckett
So how do GlocalSearch and the Google Maps website itself get around it?
Stewart
@Stewart - Google's license allows them to search it, but doesn't allow them to redistribute it.
Chris B
But a third party putting some code on its website to ask Google "Where is this postcode?" is still only searching it, not redistributing it. So what's that to do with it? Besides, GlocalSearch is already something that anybody can use on a website, so why should equivalent server-side code be any different?
Stewart
Using global search via Google's site is more limited. You can do IIRC 6 free lookups per day on the Royal Mails website but you can't get the data for free.
Martin Beckett
+1  A: 

I found the answer in the end. Google provides access to the server-side scripts underlying the Ajax API for non-JS applications, so I just had to follow the instructions and reference on the Google site. Local Search is the one of relevance here.

Stewart
A: 

Google API free does not have a UK license for postcodes hence the accuracy of using Google maps for store Locators is very poor. They also cannot Gecode Ireland, Developers and agency's have awful get rounds which often show US towns instead of UK as only based on the first 4 digits of a postcode.

In all, no professional would use Google as there are specialists such as Bing and ViaMichelin would have the full kit available for business's

Johny Adams