Skip to content

Instantly share code, notes, and snippets.

@luizventurote
Created April 13, 2014 02:50
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 luizventurote/10566955 to your computer and use it in GitHub Desktop.
Save luizventurote/10566955 to your computer and use it in GitHub Desktop.
Converting address to latitude and longitude - Google Maps - PHP.
<?php
/**
* Converting address to latitude and longitude
*/
function setLatitudeAndLongitude($address) {
$address = urlencode($address);
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$address."&sensor=true";
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->status;
if ($status=="OK") {
$this->latitude = $xml->result->geometry->location->lat;
$this->longitude = $xml->result->geometry->location->lng;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment