-3

Trying to do the simple but something is throwing it off it seems. Just want to load a KML file from a web page.

So I've made a very simple KML file in Google Earth with one placemark on it, saved it and uploaded it to our orienteering club web site (hosted on GoDaddy if that makes any difference). I then copied the html code from the KML Layers web page and loaded it on my web site and changed the key code- worked fine.

All I did next was change the lat/long location values and then listed my own kml file, full URL, .. and it pulls up a map, centered, but with no placemark. ACK!

I've read around and am wondering if there is something server side I need to do to get the KML to be read? Since it's a GoDaddy host, I have no control over it if this is the issue.

The KML only lists one Placemark and I've read through the Google Maps schema and it all seems legit. Here it is anyway.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>Test1</name>
    <Style id="s_ylw-pushpin">
        <IconStyle>
            <scale>1.3</scale>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
            </Icon>
            <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
        </IconStyle>
    </Style>
    <Placemark>
        <name>testmark</name>
        <styleUrl>#s_ylw-pushpin</styleUrl>
        <Point>
            <gx:drawOrder>1</gx:drawOrder>
            <coordinates>-73.20975393157571,44.46282408596932,0</coordinates>
        </Point>
    </Placemark>
</Document>
</kml>

As noted I'm just using the exact same text from the KML Layers web page and have changed the location to my lat/long (working) but the kml file is never found. "... var ctaLayer = new google.maps.KmlLayer({ url: "http://www.gmoclub.org/kml/8gove3.kml", map: map ..."

Have tried in several browsers as well. IE blocked it with a message bar that wouldn't clear about Active X controls, Chrome and Firefox displayed a blank map.

When I've tried several of the jsfiddle options, it alwasy fails when I add the KML link.

What am I doing wrong with the full link?!! Any notions? Sorry to be such a nube but ... it happens.

Tall Paul
  • 1
  • 3
  • 1
    Have you checked the content-type (mime-type) from the server? Sometimes when you post files to file servers, the url is to a web page that auto-loads the content via JavaScript not the KML content itself. Did you verify the URL is the content - try something like cURL to fetch the URL first. – CodeMonkey May 18 '17 at 21:58

2 Answers2

0

So the answer was twofold and was tied to both MIME Types and a fully public URL.

  1. MIME Types: So my site is hosted on GoDaddy and since you have no control over the MIME Types as you do on a full on Windows server you need to add a web.config file, which I noted above. Adding that seemed to be the key but with GoDaddy you have to wait possibly >~24 hours for it to register. An agonizing time period especially when they don't tell you it's taking effect. You just have to keep trying ... talk about annoying.

  2. Fully public URL: So this one falls under "You've gotta be kidding me" in that I knew my website was public, and the html file would load and center the base map, but no KML was being rendered. The issue was my link started out "https://godaddy ..." when it didn't need the 's' in it for the KML link, just "http://. ACK! The script I was using somehow got an 's' in there and that was the end of that working.

So between the two, it wasn't going to work. Might have seen the 's' but I'd never have found the MIME Types issue. Big thanks guys!!

Tall Paul
  • 1
  • 3
-1

The KML file has to be publicly accessible (not behind a password/login) in order for Earth and Maps to be able to access and load it. The URL you provided leads to a 404 page on your server... so maybe the file is no longer there, or it's not letting me access it because I'm not authenticated/logged-in? Try putting the KML somewhere you're 100% sure is public (test accessing it through an incognito tab).

As JasonM1 mentioned in the comment, you'll also need to make sure the MIME type is set correctly on the served file. If you get the file up somewhere public, but keep getting the raw XML instead of a KML file download, then check the MIME type setting.

If you really just want to add one point to your Google Map, it might be easier to use the Maps API options to add a Marker.

Oh, and the sample KML you provided looks and works fine for me, when I copy it straight into Earth.

Christiaan Adams
  • 1,257
  • 1
  • 7
  • 13
  • MIME types ... never did that for sure. Quick web search gives me this for a web.config file, but when I load it to the root directory, the maps are still don't load the Placemark. – Tall Paul May 19 '17 at 00:10
  • Right... I figured your KMLs were more than one point. :-) For the MIME types, looks like that should be correct, but hard to confirm without a working KML URL. Would it be possible to share a working KML link, to verify the MIME issues and try other debugging? FYI that the documentation on MIME types is at the bottom of this page: https://developers.google.com/kml/documentation/kml_tut#kml_server – Christiaan Adams May 19 '17 at 07:11