Created
May 4, 2012 18:46
-
-
Save emersonbroga/2596899 to your computer and use it in GitHub Desktop.
Emerson Carvalho.com >> Pegar Coordenadas Geográficas à partir de um endereço (snippet 1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$address = 'Praça Sete de Setembro - Belo Horizonte Minas Gerais '; | |
$lat = null; | |
$lng = null; | |
$request_url = 'http://maps.google.com/maps/geo?output=xml&q='.urlencode( $address ); | |
$xml = simplexml_load_file($request_url) or die("url not loading"); | |
$status = $xml->Response->Status->code; | |
if (strcmp($status, "200") == 0) | |
{ | |
// Successful geocode | |
$coordinates = $xml->Response->Placemark->Point->coordinates; | |
$coordinatesSplit = split(",", $coordinates); | |
// Format: Longitude, Latitude, Altitude | |
$lat = $coordinatesSplit[1]; | |
$lng = $coordinatesSplit[0]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment