Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you are looking for the <a href="http://en.wikipedia.org/wiki/Geographical_distance" rel="nofollow noreferrer">geographic distance</a>, first you need to get the latitude and longitude of your two postcodes with the <a href="http://code.google.com/apis/maps/documentation/geocoding/index.html" rel="nofollow noreferrer">Google Maps server-side geocoding services</a> as in the following example:</p> <pre><code>$url = 'http://maps.google.com/maps/geo?q=EC3M,+UK&amp;output=csv&amp;sensor=false'; $data = @file_get_contents($url); $result = explode(",", $data); echo $result[0]; // status code echo $result[1]; // accuracy echo $result[2]; // latitude echo $result[3]; // longitude </code></pre> <p>Then you can calculate the distance between the coordinates of your two postcodes by using a <a href="http://en.wikipedia.org/wiki/Great-circle_distance" rel="nofollow noreferrer">great-circle distance</a> implementation such as the following:</p> <ul> <li><a href="http://snipplr.com/view/2531/calculate-the-distance-between-two-coordinates-latitude-longitude/" rel="nofollow noreferrer">Snipplr - Calculate distance between two coordinates in PHP</a></li> </ul> <p>Note that the server-side geocoding service may only be used in conjunction with displaying results on a Google map; geocoding results without displaying them on a map is prohibited by the <a href="http://code.google.com/apis/maps/terms.html#section_10_12" rel="nofollow noreferrer">Google Maps API Terms of Service License Restrictions</a>.</p> <hr> <p><strong>UPDATE:</strong> </p> <p>If you are looking for the driving distance instead of the geographical distance, note that there is no documented and approved method at the moment to access the Google Maps Directions API via an HTTP request on the server-side. </p> <p>Nevertheless, an undocumented method that returns a JSON output is the following:</p> <pre><code>http://maps.google.com/maps/nav?q=from:London%20to:Dover </code></pre> <p>This will return you the driving directions, along with the total driving distance in JSON format: <code>"meters":122977</code>.</p> <p>The format of the <code>q</code> parameter should be <code>from:xxx%20to:yyy</code>. Replace xxx and yyy with the start and destination respectively. You can use latitude and a longitude coordinates instead of full addresses:</p> <pre><code>http://maps.google.com/maps/nav?q=from:51.519894,-0.105667%20to:51.129079,1.306925 </code></pre> <p>Note that not only this is undocumented, but it may also violate the restrictions 10.1 and 10.5 of the <a href="http://code.google.com/apis/maps/terms.html" rel="nofollow noreferrer">Google Maps API Terms and Conditions</a>.</p> <p>You may also be interesting in checking out the following related articles:</p> <ul> <li><a href="https://stackoverflow.com/questions/1800510/">Stack Overflow: Calculate driving directions using PHP?</a></li> <li><a href="http://groups.google.com/group/Google-Maps-API/browse_thread/thread/af1dd5cbeaccf32d" rel="nofollow noreferrer">Getting distance using GDirections via URL</a></li> <li><a href="http://mufumbo.wordpress.com/2009/07/23/server-side-driving-direction-with-google-maps-api-with-php-for-wap-and-web/" rel="nofollow noreferrer">Retrieve driving directions from google maps with server-side HTTP calls and show results with static maps for WAP</a></li> <li><a href="http://www.tehuber.com/article.php?story=20080812105450589" rel="nofollow noreferrer">Google Maps and Directions, REST Interface?</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload