尝试在两个坐标之间绘制折线时,我在使用 Google Maps API v3 的 setMap 函数时遇到问题。
我检查了代码在哪里失败,alert()
并且似乎在 setMap 函数中。有谁知道为什么会发生这种情况?
function showPosition(position)
{
lat=position.coords.latitude;
lon=position.coords.longitude;
speed= position.coords.speed;
altitude = position.coords.altitude;
latlon=new google.maps.LatLng(lat, lon, speed, altitude)
mapholder=document.getElementById('mapholder')
mapholder.style.height='250px';
mapholder.style.width='500px';
var myOptions={
center:latlon,zoom:14,
mapTypeId:google.maps.MapTypeId.ROADMAP,
mapTypeControl:false,
navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL}
};
var map=new google.maps.Map(document.getElementById("mapholder"),myOptions);
var marker=new google.maps.Marker({position:latlon,map:map,title:"You are here!"});
x.innerHTML="Latitude: " + lat + " Long: " + lon;
mapRoute();
}
function mapRoute(showPosition, position){
var routeCoordinates = [
new google.maps.LatLng(53.379763, -1.4658453999999999),
new google.maps.LatLng(21.291982, -157.821856)
];
var flightPath = new google.maps.Polyline({
path: routeCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
在此先感谢,马特