Sep 14
Vor kurzem wurde mir die Frage gestellt, ob es möglich wäre einen Standort anzugeben und danach die Personen in einem Umkreis von x automatisch auswählen zu lassen. Also mal wieder brav an den PC gesetzt und losgetippt. Vielleicht braucht jemand von euch das ganze auch mal. Hier mal der Teil 1 – Koordinaten und Datenbank Update:
<?php // your database connection - everybody knows what a config file is... i hope so ;) include('config.inc.php'); // your google maps api key $key = "insert_your_key_here"; // request your addresses from the database, like the following $query = "SELECT id, street, zip, city, country, latitude, longitude FROM addresses"; $result = mysql_query($query) or die(mysql_error()); // working with the data from database while (list($id, $street, $zip, $city, $country, $latitude, $longitude) = mysql_fetch_row($result)) { if ($latitude == '0.00000000' OR $longitude == '0.00000000') { // loop through each row, submit HTTP request, output coordinates $mapaddress = urlencode("$street $zip $city $country"); // desired address $url = file_get_contents("http://maps.google.com/maps/geo?q=$mapaddress&output=xml&key=$key"); // retrieve the URL contents $page = utf8_decode($url); // parse the returned XML file $xml = new SimpleXMLElement($page); // parse the coordinate string list($longitude, $latitude, $altitude) = explode(",", $xml->Response->Placemark->Point->coordinates); // input the coordinates into database $query = "UPDATE addresses SET latitude = '$latitude', longitude = '$longitude' WHERE id = '$id'"; mysql_query($query) or die(mysql_error()); } } ?>
Sorry, dass der Code nicht so toll formatiert angezeigt wird… aber mir fehlt einfach die Zeit mich darum zu kümmern, mal eine anständige Anzeige reinzubasteln… Irgendwann muss man auch mal weg von den 2 Monitoren…
Teil 2 ist in Arbeit, wer das ganze mal bei Gelegenheit noch posten… dort geht es darum mit der “Haversine” Formel die Distanz zu berechnen… und das natürlich zu unserem angegebenen Ort.