Quick data geocoding (batch upload)

Following on from the 2 previous articles on geocoding locations and use of the google maps api. The following site is a really great tool.

http://www.batchgeocode.com/

One thing to mention is who knows how long it will last, let me know if I am wrong but I’m sure this is in direct conflict with the google maps api terms of service which states :

Also, you may not use Google Maps in a manner which gives you or any other person access to mass downloads or bulk feeds of numerical latitude and longitude coordinates.

Distance calculations with latitude and longitude

Following on from this post about obtaining latitude and longitude values for postal, area or address data using the Google Maps API, I have included below some good resources on distance calulations with examples in PHP.

http://sniptools.com/latitudeLongitude.php

http://www.zipcodeworld.com/samples/distance.php.html

Enjoy.

Darren.

Geocoding UK data (latitude & longitude) using Google maps API with PHP

Quick post if anyone is interested.

I currently have an out of date script running on my golf website golfshake.com which allows people to search for golf courses within a particular distance of a postal code in the UK. This is done by taking the latitude and longitude of a postal code and running a spatial query to find the golf courses within my database. This worked great until the free web services I was using for lat and lon postal code lookups was turned off :( unfortunately in the UK the postal data, including latitude and longitude values, is held by the Royal Mail and only available for some riduculous charge.

I’ve been meaning to fix this for some time and had bookmarked this site which had a neat script for extracting the longitude and latitude from postal codes in the UK using the Google maps API. This is great but it’s a UK only solution and works only on postal codes.

Well I’m glad to say that Google annouced at the beginning of July that UK geocoding is now available which extends to postal codes, addresses and locations.

Great I can now use the google API via a HTTP call to retrieve XML data for any location in the world but how can I use it in a PHP script ?

http://maps.google.com/maps/geo?q=90210&output=xml&key=ENTER_YOUR_API_KEY

This will return an KML file containing; search term, full address, country, area, locality, longitude and latitude etc

Obviously I could use XML functions in PHP to browse the XML DOM, great article on this exact topic, but unfortunately PHP is limited in XML functionality in versions below PHP 5. You can even use CURL if it’s installed.

Thankfully the Google maps API is quite extensive and does not just provide XML output. One simple change of the output method to csv, will output simple data in CSV comma delimited format like :

200,5,34.099558,-118.411512

Therefore for simple latitude and longitude data retriveal the PHP code is very simple indeed and is just a case of retrieving the URL and exploding the data into an array for use within your PHP code.

$address = urlencode($postal);
$url = “http://maps.google.com/maps/geo?q=$address&output=csv&key=YOUR_API_KEY”;
$content = file_get_contents($url);
$data = explode(”,”,$content );

Then you can use array calls to retrieve the data ie $data[2] will get the lat and $data[3] the lon.

WordPress Themes