1

I had a co-worker that normally worked with Google Maps and now I am creating my first map. I am using what they developed in the past and making the changes for what I need. They created a script that sets some of the map defaults, so that is why things might look slightly different.

var map = new Map();
map.loadMap();
var kml = new google.maps.KmlLayer({ url: 'http://api.mankatomn.gov/api/engineeringprojectskml', suppressInfoWindows: true });
kml.setMap(map.map);

The map loads. My KML file doesn't load. I don't get any errors in the console. When I replace the url with a different URL http://www.mankato-mn.gov/Maps/StreetConstruction/streetconstruction.ashx?id=122 it'll work just fine. My new feed does validate. Is there a issue with my web service?

Update: After a few days, I am still having the issue. So I am pretty sure this isn't a DNS issue anymore. I created a jsFiddle to see if it is my code or something else. I started with Google's sample code and changed the URL of the KML file to both my web service and to a static version of the generated file. Both are valid KML files. Neither work. If there was a syntax error, wouldn't the API report that?

Mike Wills
  • 20,959
  • 28
  • 93
  • 149
  • Server: google-public-dns-a.google.com | Address: 8.8.8.8 | Non-authoritative answer: Name: api.mankatomn.gov | Address: 216.114.254.155 This is google public DNS. Maybe you could try reaching your KML with the IP address? – MrUpsidown Nov 14 '14 at 17:13
  • The server requires the domain to route to the proper application. Otherwise, I did think of that. – Mike Wills Nov 14 '14 at 17:14
  • You could try to do a DNS Lookup (nslookup) from the server where your application runs, if you have access to a shell or some tool to do so. This would confirm if your server can find the domain. – MrUpsidown Nov 14 '14 at 17:18
  • Your KML is being served with the wrong MIME type. See [this related question](http://stackoverflow.com/questions/19501713/why-not-doesnt-google-maps-view-the-kml-layout/19501959#19501959). The content [works for me](http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmztest_linktoB.html?filename=http://www.geocodezip.com/geoxml3_test/kml/engineeringprojectskml.xml) (if I download it and serve it from my server) – geocodezip Nov 14 '14 at 18:14
  • I was duplicating the other service. I know the MIME type needs to be changed yet. It didn't work either way. – Mike Wills Nov 14 '14 at 18:15

2 Answers2

1

You can get the status of a KML layer with

kml.getStatus();

which in this case return:

"INVALID_DOCUMENT"

Now, if I request your URL from the browser, I get

<Error>
   <Message>An error has occurred.</Message>
</Error>

So it seems if there ever was a valid KML there, it isn't anymore. Assuming from your question I can oly guess it was above weight limit, or you weren't associating it with a valid instance of map.

For getStatus to return something useful, you must wait for Google Maps API to try and load the KML layer you declared. For example, you can add a listener on the status_changed event.

var kmloptions={ 
    url: 'https://dl.dropboxusercontent.com/u/2732434/engineeringprojectskml.kml',     
    suppressInfoWindows: true 
};
var newKml = new google.maps.KmlLayer(kmloptions);
newKml.setMap(map);

google.maps.event.addListenerOnce(newKml, 'status_changed', function () {
    console.log('KML status is', newKml.getStatus());
});

in this case (note that I'm using the alternative URL you used in the jsFiddle), I still get INVALID DOCUMENT.

Update: it seems the problem was the encoding of the file (UTF-16 BE is meant to be binary). I converted it to utf-8 and reindented (it's in my public dropbox now)

enter image description here

ffflabs
  • 17,166
  • 5
  • 51
  • 77
  • I fixed the service, I was trying something else as you were testing. As I am playing with `getStatus()`, I am getting undefined. Not much help there. – Mike Wills Nov 17 '14 at 15:54
  • I guess getStatus won't work synchronously, please see my edited answer. – ffflabs Nov 17 '14 at 16:05
  • Thanks for the help! That was the problem. I changed it thinking that would fix the validation, but it broke it. – Mike Wills Nov 17 '14 at 16:28
0

You can check if the DNS is setup by:

  1. Going to the url in your browser. Do this with cache emptied and history ereased (private mode is best). If it ends up at your server and the right file it is not a DNS problem.
  2. Move the file to a location you're sure it is reachable without any DNS issues. e.g. http://www.mankato-mn.gov/Maps/StreetConstruction/engineeringprojectskml

If the problem persists make sure that your KML syntax and Javascript is 100% correct. Also check out https://developers.google.com/maps/documentation/javascript/examples/layer-kml if you're still having any issues.

Casper
  • 419
  • 1
  • 4
  • 16
  • The problem with your method of testing the DNS is that our ISP hosts our DNS. So we are guaranteed to have it work. I can't vouch for the rest of the world. http://www.isup.me/api.mankatomn.gov says it is visble, but I also know that full propegation takes up to 3 days sometimes. – Mike Wills Nov 14 '14 at 16:17
  • Moving the "file" is not possible. I am using ASP.NET WebApi to publish a dynamically generated file. The old site doesn't support that. – Mike Wills Nov 14 '14 at 16:18