程序生成的KML文件可以验证,但不能正常工作 [英] Program-generated KML file validates, but doesn't work

查看:50
本文介绍了程序生成的KML文件可以验证,但不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通常与Google Maps合作的同事,现在我正在创建我的第一张地图.我正在使用他们过去开发的软件,并根据我的需要进行更改.他们创建了一个脚本,该脚本设置了一些地图默认设置,这就是为什么外观可能略有不同的原因.

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);

地图加载.我的KML文件未加载.我在控制台中没有任何错误.当我将URL替换为其他URL http://www.mankato-mn.gov/Maps/StreetConstruction/streetconstruction.ashx?id=122 时,它将正常工作.我的新Feed确实通过了验证.我的网络服务有问题吗?

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?

更新:几天后,我仍然遇到问题.因此,我很确定这不再是DNS问题.我创建了一个 jsFiddle 看看它是我的代码还是其他代码.我从 Google的示例代码开始,然后更改了KML的网址文件同时存储到我的Web服务和生成文件的静态版本中.两者都是 有效 KML文件.都不起作用.如果出现语法错误,API不会报告该错误吗?

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?

推荐答案

您可以通过以下方式获取KML层的状态:

You can get the status of a KML layer with

kml.getStatus();

在这种情况下返回:

"INVALID_DOCUMENT"

现在,如果我从浏览器请求您的URL,我会得到

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

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

因此,似乎那里曾经有一个有效的KML,现在已经不存在了.根据您的问题,我可以猜测它超出了重量限制,或者您没有将其与有效的map实例相关联.

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.

为使getStatus返回有用的内容,您必须等待Google Maps API尝试加载声明的KML图层.例如,您可以在status_changed事件上添加一个侦听器.

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());
});

在这种情况下(请注意,我使用的是您在jsFiddle中使用的备用URL),我仍然得到INVALID DOCUMENT.

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

更新:看来问题出在文件的编码(UTF-16 BE是二进制文件).我将其转换为utf-8并重新缩进了(它现在在我的公共保管箱中)

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)

这篇关于程序生成的KML文件可以验证,但不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆