mysql_host, $this->mysql_user, $this->mysql_password) or die("Connection Error! (".$this->mysql_user."@".$this->mysql_host.")"); mysql_select_db($this->mysql_database) or die("Select Error!"); } // Display a list of all saved items as XML function displayMarkers() { header("Content-type: text/xml; charset=ISO-8859-1"); echo ""; echo ''; $query = "SELECT * FROM items WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: '.mysql_error()); } while ($row = @mysql_fetch_assoc($result)){ $geocoded = $this->geocodeAddress($row['street']." ".$row['nr']." ".$row['town']." ".$row['country']); echo ''; } echo ''; } // Translate cleartext addresses to latitutional and longitudional coordinates using the GMaps API function geocodeAddress($address) { $delay = 0; $base_url = "http://".$this->gmaps_host."/maps/geo?output=csv&key=".$this->gmaps_key; $geocode_pending = true; while($geocode_pending) { // Address of GMaps geocode service // We get comma sepparated coordinates on successful geocoding $request_url = $base_url."&q=".urlencode($address); $csv = file_get_contents($request_url) or die("URL not loading"); $csvSplit = split(",", $csv); $status = $csvSplit[0]; $lat = $csvSplit[2]; $lng = $csvSplit[3]; // Successful geocoding if (strcmp($status, "200") == 0) { $geocode_pending = false; $lat = $csvSplit[2]; $lng = $csvSplit[3]; } // Having sent too many geocode requests else if(strcmp($status, "620") == 0) { $delay += 100000; } // On geocoding failure else { $geocode_pending = false; echo "Address ".$address." failed to geocode. Received status ".$status."\n"; } usleep($delay); } return $coords = array($lat, $lng); } } // create a instance of the MapSomeStuff object $obj = new MapSomeStuff(); // Display markers and stop script execution if (@$_GET["display"] == "markers") { $obj->displayMarkers(); die(); } ?> MapSomeStuff
From (Street, Zip, Town):
To (Street, Zip, Town):