Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Created May 4, 2012 18:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emersonbroga/2596899 to your computer and use it in GitHub Desktop.
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)
<?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