-
-
Save maxyc/e36791086e0356f85c12 to your computer and use it in GitHub Desktop.
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 | |
// Google Maps API key | |
$key = key; // Google API key | |
$mapaddress = urlencode($listing['street_number'] . " " . $listing['street_direction'] . " " . $listing['street'] . " " . $listing['street_suffix'] . " " . $listing['street_suffix2'] . ", " . $listing['city'] . ", " . $listing['state'] . " " . $listing['zip']); | |
function geocoder($mapaddress){ | |
global $key; | |
// Desired address | |
$url = "http://maps.google.com/maps/geo?q=$mapaddress&output=xml&key=$key"; | |
// Retrieve the URL contents | |
$page = file_get_contents($url); | |
// Parse the returned XML file | |
$xml = new SimpleXMLElement($page); | |
// Parse the coordinate string | |
list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates); | |
$g_address = addslashes($xml->Response->Placemark->address); | |
$status = $xml->Response->Status->code; | |
$google_coordinates = $xml->Response->Placemark->Point->coordinates; | |
if ($status == 200) { | |
// got legit code back, so save the lat/lon | |
} elseif ($status == 602) { | |
// invalid address so post error message and let them manually add marker | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment