Google Maps Distance (DistanceMatrix) API for UK in JSON

The postcode code has been updated to use Google’s distancematrix api, which provides a very different set of data from the old “as the bird flies” calculation (it calculates road distance, and provides transport options etc).

The following code is merely a demonstration, which can be seen here.

// Specify Postcodes to Geocode
$postcode1 = 'BH151DA';
$postcode2 = 'BH213AP';

// Set and retrieve the query URL
$request = "" . $postcode1 . "&destinations=" . $postcode2 . "&mode=driving&language=en-GB&sensor=false&units=imperial";
$distdata = file_get_contents($request);

// Put the data into an array for easy access
$distances = json_decode($distdata, true);

// Do some error checking, first for if the response is ok
$status = $distances["status"];
$row_status = $distances["rows"][0]["elements"][0]["status"];

if ($status == "OK" && $row_status == "OK") {

// Calculate the distance in miles
$distance = $distances["rows"][0]["elements"][0]["distance"]["value"];
$distance_miles = round($distance * 0.621371192/1000, 2);

echo 'The distance between '.$postcode1.' and '.$postcode2.' is '.($distance/1000).'Km ('.$distance_miles.' miles).';

} else {
    echo "Calculating the distance between your locations caused an error.";


Having better error checking would also be a good idea if you plan to use the above code. Using &unit=imperial is optional, as Google always returns metres – so the code runs a basic calculation on these to convert to miles. and the Google Base Connector – Upload direct!

Not that long ago, Google offered a “Google Base Connector” which basically loaded up your ebay store and transferred all your products to Google Base.

Also not that long ago, eBay started putting its own feed on Google Base – and recently Google stopped supporting the base connector because of this.

There are several problems here.

  1. eBay do not include everybody’s products. Just do a search and you’ll find that lots of people have suffered falling sales due to the demise of the google base connector.
  2. You no longer have any control about when the feed can be uploaded to base – you’re trusting eBay to include you.
  3. You can’t brand your eBay store as your own – on google base your store comes up as “” as opposed to your merchant name.

There’s an easy fix for people with eBay stores though. Simply hit “Manage my shop” and go to “Listing Feeds” here. Enable feeds and copy your google base specific feed address (will be “”).

Now head over to base and register this data feed with the name “yourstorename.htm” (changing your store name for the one in the link). Head to the settings tab up the top and paste the ebay link into the “Website URL (Optional)” box, then hit submit.

Now all you have to do is go back to the data-feed page, and create a schedule with the link you got earlier & a date and time to get the file every day, week or month.

All that’s left now is to sit back and wait!

The key thing here is using “” for both the website address AND feed address. If you try and use anything else it’ll fail. Also make sure the rest of the settings on your account look ok before you submit your first feed 🙂