Note that there are some explanatory texts on larger screens.

plurals
  1. POCan get JSON from Google Maps call
    text
    copied!<p>I have managed to get the longitude and latitude of postcodes from Google Maps but I am unable to then get the distance between the two. The following url gives me some JSON:</p> <pre><code>https://maps.googleapis.com/maps/api/distancematrix/json?origins=51.6896118,-0.7846495&amp;destinations=51.7651382,-3.7914676&amp;units=imperial&amp;sensor=false </code></pre> <p>But I can't strip it out using PHP:</p> <pre><code>&lt;?php $du = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=51.6896118,-0.7846495&amp;destinations=51.7651382,-3.7914676&amp;units=imperial&amp;sensor=false"; $djd = json_decode(utf8_encode($du),true); print("-".$djd."-"); ?&gt; </code></pre> <p>Anybody know why this is?</p> <p><strong>EDIT</strong></p> <p>The following worked just fine:</p> <pre><code>&lt;?php $pc1 = 'SA92NH'; $pc2 = 'HP270SW'; $url1 = "https://maps.googleapis.com/maps/api/geocode/json?address=".$pc1."&amp;sensor=false"; $url2 = "https://maps.googleapis.com/maps/api/geocode/json?address=".$pc2."&amp;sensor=false"; $url1_data = file_get_contents($url1); $url2_data = file_get_contents($url2); $json1_data = json_decode(utf8_encode($url1_data),true); $json2_data = json_decode(utf8_encode($url2_data),true); $longlat1 = $json1_data['results'][0]['geometry']['location']['lat'].",".$json1_data['results'][0]['geometry']['location']['lng']; $longlat2 = $json2_data['results'][0]['geometry']['location']['lat'].",".$json2_data['results'][0]['geometry']['location']['lng']; print($longlat1."&lt;br&gt;\n"); print($longlat2."&lt;br&gt;\n"); ?&gt; </code></pre>
 

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