First of all, I hope this is the right place to post this.
I run a website which, among other things, is attempting to record
details of every railway accident which has ever occurred in the UK. I
have a google map at:
http://www.railwaysarchive.co.uk/eventlisting.php?view=map (give it a
few seconds, theres nearly 1000 data points!)
And now I want to present the same data in GE.
I am fairly new to this kml lark, but I am stumped, being currently
unable to produce a kml file which will open in GE instead of my
browser.
OK, here's what I'm trying to do.
- I have railway accident data, inc latitude and longitude, in a mySQL
database.
- I want to have a php script called events.kml, which will extract
the data from mySQL and create valid kml.
- Then I want the resulting events.kml data to open in GE when linked
from a web browser.
With my previous experience in creating RSS feeds the same way, I
assumed I would need:
1. An apache handler to tell apache to run the .kml file (containing
php) on the server through the php engine;
2. A user-defined MIME type to force the browser to open the file in
GE rather than display in the browser.
Here is my apache handler setup:
http://www.railwaysarchive.co.uk/temp/handlers.jpg
and here is my MIME type setup:
http://www.railwaysarchive.co.uk/temp/mime%20type.jpg
and here is the resulting kml file:
http://www.railwaysarchive.co.uk/events.kml
If you save a copy of this file and open it in GE, you will see that
it plays nice. But, I, and every one of my users who has google earth
and has responded, is seeing the same thing: kml data presented in the
browser. I have tried this in IE, firefox and opera.
So what is going wrong? I have been playing email tennis with my web
hosts support for a couple of days now. They have tried various
things, including adding a handler which sent the kml file to GE
without first parsing through the php engine(!), before concluding:
"I do not think what you are trying to do is possible under suPHP on
our servers."
Is he right? I can't believe he is. Can anyone help this poor kml
newbie?
Here is my events.kml file as it is sitting on the server. I know this
isn't great php, but that's not really the issue here:
++++++++++++++++++++++++++
<?php
# script to generate google earth kml file for all events
#connect to db, get sql, etc
include("./includes/config.inc");
include("./includes/sql.inc");
include("./includes/functions.inc");
# get the data
$result = getEventsWithGeodata();
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
?>
<kml xmlns="
http://earth.google.com/kml/2.2">
<Folder>
<name>Railways Archive: UK Railway Accidents</name>
<description>All UK railway accidents in our database for which
geodata is available</description>
<?php
while ($row = mysql_fetch_array($result)) {
# loop through events
printf("<Placemark><name></name><description><a href=\"http://
www.railwaysarchive.co.uk/eventsummary.php?eventID=%s\">%s</a><p/>",
$row[eventID], htmlspecialchars(getEventName ($row, "long")));
# create image path
$imagepath = $imageLocation . "/event" . $row[eventID] . ".jpg";
if (is_file($imagepath)) {
# check for image
printf("<img src=\"
http://www.railwaysarchive.co.uk/images/event
%s.jpg\"></img>", $row[eventID]);
}
printf("</description><Point><coordinates>%s,%s,0</coordinates></
Point></Placemark>", $row[dblLongitude], $row[dblLatitude]);
}
?>
</Folder>
</kml>
++++++++++++++++++++++++++++