Generation of dynamic kml files

I have a number of geographical datasets in a database that I would like to visualize as kml-files. For google earth to behave correctly, it is not just enough that the “Content-Type” is correctly set. The file must end with a .kml.

Again, mod_rewrite to the rescue. The following line in my .htaccess file:

RewriteRule dataset-(.*).kml$ /mobilweb/kml.php?fileid=$1

I.e, when I make an url that ends with fileid-.kml, that is internally forwarded to the apacheserver that runs kml.php?fileid= and returns the result as the abovementioned kml-file. Google earth then opens the file and displays it just fine. (of cource given that the kml is correctly made…) I can also add some more info in the kml-name by using a more advanced .htaccess E.g.

RewriteRule dataset(.*)-(.*).kml$ /mobilweb/kml.php?fileid=$2&color=$1 

Here I specify a colorcode just followint the keyword dataset, the id comes after the hyphen. Of cource, I must sanitize the id and color codes correctly in the script and also handle it correctly if they are invalid or missing.

This entry was posted in Diverse, kml. Bookmark the permalink.