<?php
$username="******";
$password="*******";
$database = "********";
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
if (isset($_GET['adres']) and isset($_GET['plaats']) and isset($_GET['naam']) and isset($_GET['send'])){
$KEY = "ABQIAAAAHjylhKif972SW1KwgQ78NhQuklAhWvwoNP6gWbnSwfCX0EjbvRStD8wqyOOaTkHsg-v87ZduAhf3rg"; // Google Maps API Key hier
$base_url = "http://maps.google.nl/maps/geo?output=xml" . "&key=" . $KEY;
$address = $_GET['adres'] .' '. $_GET['plaats'];
$request_url = $base_url . "&q=" . urlencode($address);
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
// Successful geocode
$coordinates = $xml->Response->Placemark->Point->coordinates;
$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
$lat = $coordinatesSplit[1];
$lng = $coordinatesSplit[0];
$query = "insert into markers (lng, lat, name, address, type) values ('". mysql_real_escape_string($lng) ."','". mysql_real_escape_string($lat) ."', '".$_GET['naam']."', '".$address."','bar');";
$result = mysql_query($query);
if($result){
echo $address .' verwerkt, <a href="googlemapspage.php">ga naar de kaart</a>';
} else {
echo 'Er is een fout opgetreden! MySQL zegt: '. mysql_error();
}
}else {
echo 'Er is een fout opgetreden! MySQL zegt: '. mysql_error();
} exit();
}
elseif (isset($_GET['send'])){
echo "<from action='googlemapspage.php' method='POST' name='message'>
<input type='hidden' name='message' value='je hebt niet alle velden ingevuld'>
</form";
echo "<script languages='javascript'>
window.document.message.submit();
</script>";
exit();}
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . $row['type'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>