2
With the code below I can calculate the distance from one city to another, but I can only put cep’s would have some way to use the city’s own names instead of cep’s ?
$i = 0;
$arr = array('90450000','95180000');
foreach ($arr as &$valuedestino) {
$origin = '95700000';
$destino = $valuedestino;
$url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=$origin&destinations=$destino&mode=driving&language=en-EN&sensor=false";
$data = @file_get_contents($url);
$result = json_decode($data, true);
foreach($result['rows'] as $distance) {
$i++;
echo '<br>';
echo "$i - Distance from you: " . $distance['elements'][0]['distance']['text'] . ' (' . $distance['elements'][0]['duration']['text'] . ' in current traffic)';
}
}