Problem with handlers and MIME type

55 views
Skip to first unread message

goo...@holtheights.eclipse.co.uk

unread,
Jul 6, 2008, 5:52:49 AM7/6/08
to KML Developer Support - KML Server Side Scripting
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>

++++++++++++++++++++++++++++

goo...@holtheights.eclipse.co.uk

unread,
Jul 6, 2008, 2:21:13 PM7/6/08
to KML Developer Support - KML Server Side Scripting
Why do I always solve problems just after I post them on the interweb?

I was about to give up and do a kludge instead - have a .php file to
write a kml file and run it as a cron job. I was browsing some sample
scripts and came across this line in a php script:

header('Content-type: application/vnd.google-earth.kml+xml');

put this at the top of your file output and bingo! opens in GE.

On Jul 6, 10:52 am, "[email address]" wrote:
> 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
> printf("<Placemark><name></name><description><a href=\"http://www.railwaysarchive.co.uk/eventsummary.php?eventID=%s\">%s</a><p/>",

barryhunter [KML Guru]

unread,
Jul 11, 2008, 5:13:46 PM7/11/08
to KML Developer Support - KML Server Side Scripting
Great that you solved it. I did notice another anomaly, in the
mimetypes screenshot, you have a .kml at the end of the type, which i
dont beleive should be, that might also of solved it. (but its good
practice to use the header() anyway to output the content type in case
you run it on a server without the handlers thing)

On Jul 6, 7:21 pm, "[email address]" wrote:
> Why do I always solve problems just after I post them on the interweb?
>
> I was about to give up and do a kludge instead - have a .php file to
> write a kml file and run it as a cron job. I was browsing some sample
> scripts and came across this line in a php script:
>
> header('Content-type: application/vnd.google-earth.kml+xml');
>
> put this at the top of your file output and bingo! opens in GE.
>
> On Jul 6, 10:52 am, "[email address]" wrote:
>
> > 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(giveit a

barryhunter [KML Guru]

unread,
Jul 11, 2008, 5:20:46 PM7/11/08
to KML Developer Support - KML Server Side Scripting
Ah, while here do also have another tip. Wrap your file in a network
link.

What I mean is create a small kml file that simply contains a
networklink pointing to the above url. The benefit being that if you
add new events (a sad reality) then users who have already clicked
your link will get the contnent automatically (eg the next time they
load GE) - otherwise they download a static copy of the data that
doesnt update.

eg
http://www.railwaysarchive.co.uk/events_link.kml
returns (you of course willprobably have to output it via php because
ofthe handler!)

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<NetworkLink>
<name>Railways Archive: UK Railway Accidents</name>
<description>All UK railway accidents in our database for which
geodata is available</description>
<Url>
<href>http://www.railwaysarchive.co.uk/events.kml</href>
</Url>
</NetworkLink>
</kml>

then you only ever give out
http://www.railwaysarchive.co.uk/events_link.kml
- the events.kml file is hidden...
Reply all
Reply to author
Forward
0 new messages