GMaps API V3 not loading kml when a parameter is included in the url of the kml

237 views
Skip to first unread message

Paulweb

unread,
Jun 21, 2011, 3:18:28 PM6/21/11
to Google Maps JavaScript API v3
My GMaps API V3 page loads a kml file fine if there is no parameter
passed to the kml file

e.g. var hilllayer = new google.maps.KmlLayer('http://
www.walkhighlands.co.uk/munros/bagged.kml', { preserveViewport :
true });

but as soon as I add a parameter it just doesn't load.

e.g. var hilllayer = new google.maps.KmlLayer('http://
www.walkhighlands.co.uk/munros/bagged.kml?usid=2508',
{ preserveViewport : true });

This is true even if a nonsense parameter which isn't used by the kml
is passed.

See
http://www.walkhighlands.co.uk/munros/hills-pages

Many, many thanks for any help.

geoco...@gmail.com

unread,
Jun 21, 2011, 3:51:56 PM6/21/11
to Google Maps JavaScript API v3
On Jun 21, 12:18 pm, Paulweb <walkhighla...@gmail.com> wrote:
> My GMaps API V3 page loads a kml file fine if there is no parameter
> passed to the kml file
>
> e.g. var hilllayer = new google.maps.KmlLayer('http://www.walkhighlands.co.uk/munros/bagged.kml', { preserveViewport :
> true });
>
> but as soon as I add a parameter it just doesn't load.

Because your server isn't generating valid xml when you do that. I
see this if I look at the "kml" directly:
[phpBB Debug] PHP Notice: in file /home/walkhigh/public_html/munros/
bagged.kml on line 8: mysql_fetch_array(): supplied argument is not a
valid MySQL result resource

If I remove the parameter, the kml is valid.

-- Larry

>
> e.g. var hilllayer = new google.maps.KmlLayer('http://www.walkhighlands.co.uk/munros/bagged.kml?usid=2508',
> { preserveViewport : true });
>
> This is true even if a nonsense parameter which isn't used by the kml
> is passed.
>
> Seehttp://www.walkhighlands.co.uk/munros/hills-pages

Rossko

unread,
Jun 21, 2011, 5:35:07 PM6/21/11
to Google Maps JavaScript API v3
> Because your server isn't generating valid xml when you do that.  I
> see this if I look at the "kml" directly:
> [phpBB Debug] PHP Notice: ...

How curious, I couldn't see anything like that in source earlier.

For OP, its worth knowing that Google caches your KML for some time.
Meaning, if you have say a php error for bagged.kml?usid=2508 and
later fix the error, Google may keep trying to use the 'bad' version
for some hours. bagged.kml?bananas=skin would get a new version.

Paulweb

unread,
Jun 21, 2011, 4:02:22 PM6/21/11
to Google Maps JavaScript API v3
That's very odd - I get valid kml when I look at the files, e.g.
http://www.walkhighlands.co.uk/munros/bagged.kml?usid=619

In fact no matter what parameter I enter.


On Jun 21, 8:51 pm, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:

geoco...@gmail.com

unread,
Jun 22, 2011, 1:09:50 AM6/22/11
to Google Maps JavaScript API v3
On Jun 21, 1:02 pm, Paulweb <walkhighla...@gmail.com> wrote:
> That's very odd - I get valid kml when I look at the files, e.g.

http://www.walkhighlands.co.uk/munros/bagged.kml?usid=619

I no longer see the error. But feedvalidator doesn't like the
"'" (single quote) characters...
http://www.feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.walkhighlands.co.uk%2Fmunros%2Fbagged.kml%3Fusid%3D619


-- Larry

geoco...@gmail.com

unread,
Jun 22, 2011, 1:20:26 AM6/22/11
to Google Maps JavaScript API v3
On Jun 21, 10:09 pm, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
> On Jun 21, 1:02 pm, Paulweb <walkhighla...@gmail.com> wrote:
>
> > That's very odd - I get valid kml when I look at the files, e.g.
>
> http://www.walkhighlands.co.uk/munros/bagged.kml?usid=619
>
> I no longer see the error.  But feedvalidator doesn't like the
> "'" (single quote) characters...http://www.feedvalidator.org/check.cgi?url=http%3A%2F%2Fwww.walkhighl...

Oops, I misinterpreted what it was saying. It says this:

Congratulations!
This is a valid KML 2.2 feed.
Recommendations
This feed is valid, but interoperability with the widest range of feed
readers could be improved by implementing the following
recommendations.

Feeds should not be served with the "text/html" media type

Paulweb

unread,
Jun 22, 2011, 2:58:31 AM6/22/11
to google-map...@googlegroups.com
Rossko

I get just using bagged.kml working fine, and it works fine too if I change the name to, say, bagged-new.kml to check it isn't just the cache.

But whatever parameters I put - even if put bagged.kml?bananas=skin - then the kml doesn't load. :(

Paulweb

unread,
Jun 22, 2011, 3:44:07 AM6/22/11
to Google Maps JavaScript API v3
It also doesn't work if I change the extension away from .kml - to
say .php, even if it contains valid kml

So it seems that maybe my GMaps isn't recognising any files as .kml
files unless .kml is the last 4 characters of the url passed to it.
Why could this be happening?

Rossko

unread,
Jun 22, 2011, 4:11:32 AM6/22/11
to Google Maps JavaScript API v3
> So it seems that maybe my GMaps isn't recognising any files as .kml
> files unless .kml is the last 4 characters of the url passed to it.
> Why could this be happening?

"Feeds should not be served with the "text/html" media type "

http://code.google.com/apis/kml/documentation/kml_tut.html#kml_server

Paulweb

unread,
Jun 22, 2011, 8:35:37 AM6/22/11
to Google Maps JavaScript API v3
OK thanks.... but if I add the following line to .htaccess
AddType application/vnd.google-earth.kmz .kmz

then I can no longer parse the kml file for php. I need the file
contents to be parsed for php and then output as kml.... is that
possible?

Paulweb

unread,
Jun 22, 2011, 9:37:47 AM6/22/11
to Google Maps JavaScript API v3
Ah fixed it, thanks alot Rossco for putting us on the right track.
Just needed to add the following line to the php code that writes out
the kml file:
header('Content-type: application/vnd.google-earth.kml+xml');

Cheers
Reply all
Reply to author
Forward
0 new messages