header("Content-Type: application/vnd.google-earth.kml+xml");
$link = mysql_connect('db1.kapsi.fi', 'zache', 'CpFhuQCMf5')
or die('Could not connect: ' . mysql_error());
mysql_select_db('zache') or die('Could not select database');
$placemarks_str="";
if ($_GET['update']==1) $update=1;
else $update=0;
if (strlen($_GET['BBOX'])) {
$bbox=split(",", $_GET['BBOX']);
$west = floatval(ereg_replace("[^-0-9\.]","",$bbox[0]));
$south = floatval(ereg_replace("[^-0-9\.]","",$bbox[1]));
$east = floatval(ereg_replace("[^-0-9\.]","",$bbox[2]));
$north = floatval(ereg_replace("[^-0-9\.]","",$bbox[3]));
$query = "SELECT id, title, description, lat, lon FROM articlecoordinates WHERE needphotos=1 AND lat>$south AND lat<$north AND lon>$west AND lon<$east ORDER BY title LIMIT 100";
} else {
$query = "SELECT id, title, description, lat, lon FROM articlecoordinates WHERE needphotos=1 ORDER BY title LIMIT 100";
}
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ( $row=mysql_fetch_assoc($result)) {
if ($update==1)
$placemarks_str.=print_update_placemark($row);
else
$placemarks_str.=print_placemark($row);
}
mysql_free_result($result);
if ($update==1)
echo print_update_kml($placemarks_str);
else
echo print_kml($placemarks_str);
function print_kml($placemarks_str) {
$str="\n";
$str.="\n";
$str.="\n";
$str.="\n";
$str.="0\n";
$str.="#radioFolderExample\n";
$str.="$placemarks_str";
$str.="\n";
$str.="\n";
return $str;
}
function print_placemark($c) {
$str="
" .str_replace("_", " ", $c['title']) ."
lue lisää )]]>
" .$c['lon'] ."," .$c['lat'] .",0
";
return $str;
}
?>