【问题标题】:I'm having trouble getting scripts to run properly in different browsers?我无法让脚本在不同的浏览器中正常运行?
【发布时间】:2012-08-12 14:04:23
【问题描述】:

以下代码有问题:

function initialize() {
            //myLatLng = new google.maps.LatLng(37.422104808,-122.0838851);

            var myOptions = {
                zoom: 18,
                center: new google.maps.LatLng(42.564613,-70.809087),
                // zoom: 5,
                // center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("map_canvas"),
                  myOptions);

   geoXml = new geoXML3.parser({
                map: map,
                singleInfoWindow: true,
                afterParse: useTheData
            });
            geoXml.parse('ActivityStatus_Producing_labels.kml');
        };
function kmlClick(marker) {
  google.maps.event.trigger(geoXml.docs[0].markers[marker],"click");
}

function useTheData(doc){
  // Geodata handling goes here, using JSON properties of the doc object
 var sidebarHtml = "<table>";
 for (var i = 0; i < doc[0].markers.length; i++) {
 // console.log(doc[0].markers[i].title);
sidebarHtml += '<tr><td><a     href="javascript:kmlClick('+i+');">'+doc[0].placemarks[i].name+'</a></td></tr>';
  }

我收到一个错误,即 doc[0].markers.length 无法从 null 或不存在的变量中获取长度,具体取决于我使用的浏览器。

在这个网站上:http://thoughtfi.com/geoxmlpractice/practiceIMR2.html 我可以让它在 Chrome 但不能在 IE 中运行

这个网站在 IE 和 Chrome 下工作,代码几乎相同:http://www.geocodezip.com/geoxml3_test/v3_geoxml3_us_states_kml_test.html

如何让我的网站正常运行?我猜它没有及时解析kml文件或者服务器/浏览器解析kml太慢?

【问题讨论】:

  • function(){} 这样的函数表达式末尾没有分号。此外,您似乎在脚本末尾缺少大括号 }

标签: javascript html xml google-maps-api-3 kml


【解决方案1】:

它似乎是 kml 文件。 IE 不认为它是有效的 xml。 feedvalidator 也没有: http://www.feedvalidator.org/check.cgi?url=http%3A%2F%2Fthoughtfi.com%2Fgeoxmlpractice%2FActivityStatus_Producing_labels.kml#l675

如果我修复了无效的 xml(以及 xml 文件报告的字符编码),它对我有用:

http://www.geocodezip.com/geoxml3_test/thoughtfi_com_geoxmlpractice_practiceIMR2a.html

Here is another example 显示“固定”kml

You can also see what Google Maps thinks of your kml:

http://thoughtfi.com/geoxml... 无法显示,因为它不是有效的 KML 或 KMZ 文件。

【讨论】:

  • 甜蜜!我迫不及待想明天在装有 IE 的电脑上试试这个
  • 嗯,目前我无法使用这种方法在 chrome 和 firefox 上使用它。我基本上有相同的文件,只是我将它保存为 xml。有什么我想念的吗?
  • 我需要在我的服务器上将其保存为 xml,因为我的服务器未配置为提供 kml(您不需要这样做)。您文件的 xml 内容无效,IE(8) 无法成功解析它。
猜你喜欢
  • 2014-09-15
  • 2014-08-10
  • 2017-02-03
  • 2012-09-01
  • 2012-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多