我已经实现了一个将 KML 解析为 Google 地图的脚本,如此处所述。这里还有一个工作示例。
这在 Safari 和 IE 中效果很好,但在我的安装(仍然是本地)和演示站点上的 Firefox 或 Chrome 中没有任何反应。日志中唯一的内容是:
--[13:07:38.076] "Unable to retrieve station.kml"
有人可以看看这个并提供一些启示吗?我对 JavaScript 不够精通,无法弄清楚发生了什么。
谢谢!
更新:这是我的实际代码。
<!DOCTYPE html>
<html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Where Are Our Alumni?</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<style type="text/css">
body, html {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
div#map-canvas {
width: 100%; height: 100%;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="geoxml3.js"></script>
<script src="markerclusterer.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var myOptions = {
center: new google.maps.LatLng(41.8813571,-87.6294174),
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mcOptions = {gridSize: 50, maxZoom: 15};
var weather_url = "http://api.wunderground.com/api/6d9cb153ba3be6c0/conditions/forecast/q/";
var count = 0;
markers = [];
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
markerclusterer = new MarkerClusterer(map, [], mcOptions);
var infoWindow = new google.maps.InfoWindow({maxWidth:800});
var myParser = new geoXML3.parser({
map: map, singleInfoWindow:true,
createMarker:function(placemark){
if (placemark.point.lat != '0') {
var point = new google.maps.LatLng(placemark.point.lat, placemark.point.lng);
var marker = new google.maps.Marker({position:point});
markers.push(marker);
google.maps.event.addListener(marker, "click", function(){
var marker_lat = marker.getPosition().lat();
var marker_lng = marker.getPosition().lng();
var request_url = weather_url + (marker_lat + "," + marker_lng);
infoWindow.close();
infoWindow.setOptions({maxWidth:800});
content = ("<div><strong>" + placemark.name + "</strong><br>");
content += (placemark.description + "</div>");
infoWindow.setContent(content);
infoWindow.open(map, marker);
});
markerclusterer.addMarker(marker);
}
}
});
myParser.parse('alumni.kml');
});
function clickMarker(i){
google.maps.event.trigger(markers[i], "click");
}
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
geoxml3.js 脚本是导致错误的原因,可从此处获得。