Geocodificação – Converter Endereço em Latitude e Longitude com Google Maps

$rua = str_replace(' ',  '+', 'Avenida Atlantica');
$numero = '1702';
$cidade = str_replace(' ', '+', 'Rio de Janeiro');
$pais = 'BR';

$url = 'http://maps.google.com.br/maps/api/geocode/json?address=';
$url .= "$numero+$rua,+$cidade,+$pais&sensor=false";

$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$conteudo = curl_exec($c);
curl_close($c);

$json = json_decode($conteudo, false);

print_r($conteudo);

echo 'latitude: ', $json->results[0]->geometry->location->lat, "\n";
echo 'longitude: ', $json->results[0]->geometry->location->lng;
Advertisements

One thought on “Geocodificação – Converter Endereço em Latitude e Longitude com Google Maps

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s