I have code driven by php that tracks co-ordinates on Google Map and
has a different icon on the last co-ordinate entered. I would like the
map to open at this co-rodinate rather than the first one. Any
thoughts on how we could achieve this?
Code is as follows
[code]
<?php
function makePlacemark($line,$id)
{
// 38 degrees 22.3 N 020 degrees 42.8 E anchorage in
Ithaca 7/7/09
$t = preg_split("/[\s]+/",$line);
$north = $t[0] + $t[2]/60;
if ($t[3] == "S") $north = $north * -1;
$east = $t[4] + $t[6]/60;
if ($t[7] == "W") $east = $east * -1;
$description = "";
for ($pos = 8; $pos < count($t); $pos++)
{
$description = $description . " " . $t[$pos];
}
$pm = "
<Placemark>
<name>$description</name>
<description> </description>
<styleUrl>#$id</styleUrl>
<Point><coordinates>$east,$north,0</coordinates></Point>
</Placemark>
";
return $pm;
}
function readPlacemarks($file, $delimiter="\n\r")
{
$fp = fopen( $file, 'r' );
$placemarks = '';
$line = fgets($fp);
while ( !feof ( $fp) )
{
$placemarks = $placemarks . makePlacemark($line,"standardMark");
$line = fgets($fp);
}
$placemarks = $placemarks . makePlacemark($line,"lastMark");
return $placemarks;
}
$downloadfile="route.kml"; # give a name to appear at the client
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Type: application/vnd.google-earth.kml+xml kml;
charset=utf8");
// header("Content-Type: text/plain; charset=utf8");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
$symbol = "root://icons/palette-3.png";
$marks = readPlacemarks("marks.txt");
echo <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="
http://earth.google.com/kml/2.1">
<Document>
<name>
Our route...
</name>
<description>
The route with current location
</description>
<Style id="standardMark">
<LineStyle>
<color>7f00ffff</color>
<width>2</width>
</LineStyle>
<PolyStyle>
<color>af99cccc</color>
</PolyStyle>
</Style>
<Style id="lastMark">
<LineStyle>
<color>7f00ffff</color>
<width>2</width>
</LineStyle>
<PolyStyle>
<color>008000</color>
</PolyStyle>
<IconStyle>
<Icon>
<href>$symbol</href>
<x>64</x>
<y>32</y>
<w>32</w>
<h>32</h>
</Icon>
</IconStyle>
</Style>
$marks
</Document>
</kml>
EOD;
?>
[/code]