I am implementing Google Maps on a real estate website and I have a problem to solve: the request gives% error of% ...
Soon in the middle of the code is the result of the variable file_get_contents($url)
which if I copy and paste it into the address bar of the browser, it returns the perfect file containing all the data of that property with the address presented but the file_get_contents can not perform the same task.
Does anyone know why? Also see url that retakes error .
Code:
<?php
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// CONSULTA GOOGLE MAPS
$key = "AIzaSyCfYKBdv9RFbsHaRuUu7Pf5Ft8CrQ0wHQo";
$address =
urlencode(
$linha['ENDERECO_TIPO'].' '.
$linha['ENDERECO'].', '.
$linha['NUMERO'].' - Bairro '.
$linha['BAIRRO'].' - '.
$linha['CIDADE'].', '.
$linha['UF'].',
Brasil'
);
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".
$linha['ENDERECO_TIPO'].' '.
$linha['ENDERECO'].', '.
$linha['NUMERO'].' - Bairro '.
$linha['BAIRRO'].' - '.
$linha['CIDADE'].', '.
$linha['UF'].',
Brasil'
."&sensor=false";
echo "<strong><em>" .$url. "</em></strong><br /><br />";
# Este é o resultado da variável $url
/* http://maps.googleapis.com/maps/api/geocode/json?address=RUA FELICISSIMO DE AZEVEDO, 1 - Bairro HIGIENOPOLIS - PORTO ALEGRE, RS, Brasil&sensor=false */
$response = file_get_contents($url);
$response = json_decode($response, true);
$data['latitude'] = $response['results'][0]['geometry']['location']['lat'];
$data['longitude'] = $response['results'][0]['geometry']['location']['lng'];
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
?>
Error: failed to open stream: HTTP request failed! HTTP / 1.0 400 Bad Request in ...
If you put this code after the first $url
and $response
it appears exactly nothing: echo
... that is, file_get_contents or is not going or is not coming back.