iPhone and KML Links

140 views
Skip to first unread message

drdanger

unread,
Mar 5, 2009, 2:06:05 PM3/5/09
to KML Developer Support - KML Server Side Scripting
I'm hoping someone can help solve why I can't get a link to a KML file
to open up in the Maps app on the iPhone (or the Touch that I'm
testing on). I know there's a way to get this to work because the
following link will open up maps when clicked in an email or from
Safari:

http://maps.google.ca/maps?latlng=0,0,12442018006508482163&q=hotels&output=kml

However, if I save the KML file (http://www.crewsware.com/kmltest/
maps.kml) that gets returned by the above query and use a PHP file to
send the same headers as Google then return the exact same KML file, I
get a "Download Failed" "Safari cannot download this file." The script
is below and it works on a desktop (where it opens Earth), Blackberry
(where it opens Google Maps). It can be accessed at
http://www.crewsware.com/kmltest/kmltest.php

<?php
header("Cache-Control: private");
header("Content-Type: application/vnd.google-earth.kml+xml;
charset=UTF-8");
header("Content-Disposition: attachment; filename=\"maps.kml\"");

$foo=file_get_contents("maps.kml");
echo($foo);
?>

Any help would be appreciated.

Roman N

unread,
Mar 12, 2009, 7:20:40 PM3/12/09
to KML Developer Support - KML Server Side Scripting
Hi drdanger,

I don't know too much about the iPhone's handling of KML files, but it
**may** be looking only for URLs that end with "kml." This is only a
conjecture.

If this is indeed the case, you can fake a "KML" URL ending using URL
rewriting via Apache's mod_rewrite or the like.

You may want to also check out an iPhone OS forum.

Hope that helps,

- Roman

On Mar 5, 12:06 pm, drdanger wrote:
> I'm hoping someone can help solve why I can't get a link to a KML file
> to open up in the Maps app on the iPhone (or the Touch that I'm
> testing on). I know there's a way to get this to work because the
> following link will open up maps when clicked in an email or from
> Safari:
>
> http://maps.google.ca/maps?latlng=0,0,12442018006508482163&q=hotels&o...
>
> However, if I save the KML file (http://www.crewsware.com/kmltest/
> maps.kml) that gets returned by the above query and use a PHP file to
> send the same headers as Google then return the exact same KML file, I
> get a "Download Failed" "Safari cannot download this file." The script
> is below and it works on a desktop (where it opens Earth), Blackberry
> (where it opens Google Maps). It can be accessed athttp://www.crewsware.com/kmltest/kmltest.php

fraser

unread,
Mar 22, 2009, 9:25:34 PM3/22/09
to KML Developer Support - KML Server Side Scripting
Hi,

This is something I have been playing with too (without any joy!)
Just to let you know even using mod_rewite to swap the php/kml
extensions gives the same "Safari cannot download this file" error...

F.

KYTransportation

unread,
Mar 24, 2009, 1:40:57 PM3/24/09
to KML Developer Support - KML Server Side Scripting
Hi drdanger,

Perform a browser check for the iPhone and redirect to maps:q=http://
yoururlhere/yourlinkhere.kml

<script>
if ((navigator.userAgent.indexOf('iPhone') != -1) ||
(navigator.userAgent.indexOf('iPod') != -1))
{
document.location = "maps:q=http://yoururlhere/yourlinkhere.kml";
}
</script>


Done and done. Android can be done similarly. Your above URL ends in
output=kml, so its read in as a dynamic style KML file (Keyhole Markup
Language--a company Google bought out, and a new Google standard
easily recognized by the Apple-Google iPhone Maps app).

Hope it helps. :)

fraser

unread,
Mar 25, 2009, 5:54:44 PM3/25/09
to KML Developer Support - KML Server Side Scripting
Thank you sir :)

marc.atkinson

unread,
May 20, 2009, 5:29:45 PM5/20/09
to KML Developer Support - KML Server Side Scripting
Hello DRanger,

I ran into the same issue. It works on the BB and on a desktop, but
the iPhone can't open it. Essentially the mobile maps on the iPhone
can't open a .kml file directly.


However something like this works: http://maps.google.com/maps/geo?q=[your
address run through the replace function]ex (30+NW+11th+Ave+Portland
+Oregon)&output=kml&oe=utf8&sensor=true&key=[your google key here]

Here is the C# code to make that dynamic (from an address not
coordinates, although I am sure you could get it to work with the lat
long as well).

private string CreateGoogleMobilMapURL(string locationAddress)
{
StringBuilder sb = new StringBuilder();
sb.Append(locationAddress);
sb.Replace(' ', '+', 0, sb.Length);

string mmURL = string.Format("http://maps.google.com/maps/geo?
q={0}&output=kml&oe=utf8&sensor=true&key={1}", sb.ToString(),
ConfigurationManager.AppSettings["GoogleKey"]);

return mmURL.ToString();

}

Then just redirect (open somehow....I don't know php) and Voila!
> > Hope it helps. :)- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages