Skip to content

Instantly share code, notes, and snippets.

@flug
Last active October 31, 2019 14:28
Show Gist options
  • Select an option

  • Save flug/3efadeaa86779a3b8c67c70e0a63adb2 to your computer and use it in GitHub Desktop.

Select an option

Save flug/3efadeaa86779a3b8c67c70e0a63adb2 to your computer and use it in GitHub Desktop.
[distance map] #php #googleMap
<?php
$provenance = '26200 MONTELIMAR';
$destination = '13001 MARSEILLE';
$dom = new DOMDocument();
$dom->validateOnParse = true;
$APIMAP = 'http://maps.googleapis.com/maps/api/distancematrix/xml?origins='.$provenance.'&destinations='.$destination.'&sensor=false';
$dom->load($APIMAP);
$elemlist=$dom->getElementsByTagName('distance');
if ($elemlist->length != 0)
{
$elementDistance = $elemlist->item(0);
$valeurKmlist=$elementDistance->getElementsByTagName('value');
if ($valeurKmlist->length!=0)
{
$valeurKm=$valeurKmlist->item(0);
$resultatEnMetre = $valeurKm->firstChild->nodeValue;
$resultatkm = ceil($resultatEnMetre / 1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment