【发布时间】:2014-03-03 22:52:33
【问题描述】:
我的 HTML 如下
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Directions Complex</title>
<style>
html{height:100%;}
body{height:100%;margin:0px;font-family: Helvetica,Arial;}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/branches/polys/geoxml3.js"></script>
<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/trunk/ProjectedOverlay.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
var myOptions = {
center: new google.maps.LatLng(39.397, -100.644),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var geoXml = new geoXML3.parser({
map: map,
singleInfoWindow: true,
afterParse: useTheData
});
geoXml.parse('google_earth_tutorial_files.kml');
}
);
function useTheData(doc) {
// Geodata handling goes here, using JSON properties of the doc object
for (var i = 0; i < doc[0].markers.length; i++) {
// console.log(doc[0].markers[i].title);
jQuery('#map_text').append(doc[0].markers[i].title + ', ');
}
};
</script>
</head>
<body >
<form id="form1">
<div id="map_canvas" style="width:600px;height:500px;"></div>
<div id="map_text"></div>
</form>
</body>
</html>
但问题是,在我的机器上,开发者工具出现错误
GET google_earth_tutorial_files.kml geoxml3.js:1169
geoXML3.fetchXML geoxml3.js:1169
fetchDoc geoxml3.js:160
parse geoxml3.js:155
(anonymous function) testmypage2.html:35
n jquery.min.js:2
o.fireWith jquery.min.js:2
e.extend.ready jquery.min.js:2
c.addEventListener.B
我的 html 中的第 35 行是 geoXml.parse('google_earth_tutorial_files.kml');
我不知道为什么会这样。请帮忙。 我可以看到地图,但没有加载 KML 图层
我的 KML 是
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
<name>Manfred Mustermann</name>
<description>Manfred Mustermann</description>
<Point>
<coordinates>7.0964850607874,51.781641735074,0</coordinates>
</Point>
<address>Musterstr 29 Aachen, 52070 Nordrhein-Westfalen</address>
<styleUrl>#0</styleUrl>
</Placemark>
</kml>
【问题讨论】:
-
看起来你的“useTheData”函数有问题(这是一个 jquery 错误,这是我看到使用的唯一地方)。 KML 是什么样的?某处是否有可公开访问的版本?
-
我已经在问题中发布了 KML。我还删除了您要求我删除的代码。我现在得到 Uncaught TypeError: Cannot read property 'length' of undefined in useTheData in markers.length
-
我的 kml 不公开。它位于我的机器上
-
是的,我可以看到。显然我做错了什么。问题 - 我是从我机器上的文件夹中运行 HTML 和 KML 文件还是必须是网络服务器?如果它必须是一个网络服务器,那么如果我的网络应用程序不公开,它会有所不同吗?
标签: google-maps geoxml3