谷歌地图v2中的多段线在visual basic web浏览器中运行良好。现在谷歌地图v3返回一个错误"无法设置未定义或null引用的属性'lat'"。该应用程序以visual basic程序中的Javascript html文件的形式运行。当我直接在Internet Explorer中执行脚本时,多段线工作得很好。
有人知道可能是什么问题吗?
这是我的HTML代码:
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyDGYPgYpwZ4ZQCLCAujetDwArlVBC_S9TI&sensor=false"></script>
<script>
var map;
function initialize() {
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(36.70245,-95.7185)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
//<!var image = 'http://google.com/mapfiles/ms/micons/wht-circle.png';
var image = 'http://google.com/mapfiles/kml/paddle/wht-circle.png';
var DC = new google.maps.Marker({
position: new google.maps.LatLng(36.70245,-95.7185),
map: map,
icon: image
});
var image = "http://labs.google.com/ridefinder/images/mm_20_gray.png";
var Customer = new google.maps.Marker({
position: new google.maps.LatLng(31.291982, -95.821856),
map: map,
icon: image
});
var Customer = new google.maps.Marker({
position: new google.maps.LatLng(41.291982, -105.821856),
map: map,
icon: image
});
var polyline = [
new google.maps.LatLng(36.70245,-95.7185),
new google.maps.LatLng(31.291982, -95.821856),
];
var polyline_overlay = new google.maps.Polyline({
path: polyline,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
polyline_overlay.setMap(map);
var polyline = [
new google.maps.LatLng(36.70245,-95.7185),
new google.maps.LatLng(41.291982, -105.821856),
];
var polyline_overlay = new google.maps.Polyline({
path: polyline,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
polyline_overlay.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
对于初学者,可以删除最后一个坐标后的逗号:var折线=[新google.maps.LatLng(36.70245,-95.7185),新google.maps.LatLng(41.291982,-105.821856),];
应为:var折线=[新google.maps.LatLng(36.70245,-95.7185),new google.maps.LatLng(41.291982,-105.821856)//在此处删除逗号];