May
09
I recently developed a script that will geocode an address for work. Bellow is the simple PHP function that I’m using to geocode an address and get the lat and lng results. Simply pass the address to the function.
define("GOOGLE_MAPS_HOST", "maps.googleapis.com"); function google_geocode_address($address) { // Create the URL to retrieve the XML file $request_url = $base_url . "&address=" . urlencode($address) . '&sensor=false'; $base_url = "http://" . GOOGLE_MAPS_HOST . "/maps/api/geocode/xml?"; // Load the XML file $xml = simplexml_load_file($request_url) or die("url not loading"); $status = $xml->status; // If the returned status was OK, then continue if($status == "OK") { $coords['lat'] = $xml->result->geometry->location->lat; $coords['lng'] = $xml->result->geometry->location->lng; return $coords; } // Anything other than OK, return false. else { return false; } }
no comment untill now