0
This is the Error that is happening at the time of Sending Requests by url:
Warning: file_get_contents(https://maps.googleapis.com/maps/api/distancematrix/json?origins=Av Padres Olivetanos|Brasil&destinations=AmadorBuenoDaVeiga|Brasil&mode=car&language=pt-BR): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C:\xampp\htdocs\teste_xml\index.php on line 9
Warning: file_get_contents(https://maps.googleapis.com/maps/api/distancematrix/json?origins=Rua Francisco Amaral|Brasil&destinations=AmadorBuenoDaVeiga|Brasil&mode=car&language=pt-BR): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C:\xampp\htdocs\teste_xml\index.php on line 9
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\teste_xml\index.php on line 17
The error only happens when I loop the requests
This is the code
$dados = array('Av Padres Olivetanos', 'Rua Francisco Amaral', '');
foreach ($dados as $rua) {
//Faz a requisicao do arquivo xml
$url = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?origins=".$rua."|Brasil&destinations=AmadorBuenoDaVeiga|Brasil&mode=car&language=pt-BR");
$jsonObj = json_decode($url, true);
print_r($jsonObj);
}
//Percorre o arquivo xml
foreach($jsonObj['rows'] as $distance) {
echo 'A distancia para voce é de : ' . $distance['elements'][0]['distance']['text'];
}
The idea is that inside the foreach he calculates the distance of more than one place.
See if it helps: Google Maps with file_get_contents error. What may be?
– Bacco
William, edit your question and include the code that is generating these warnings, so that we understand the context and can assist you.
– Bruno Bermann