我试图使用Google Map API v3在Javascript中绘制动态折线,以下是我正在使用的代码段:
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var myTrip=new Array();
//var y=new google.maps.LatLng(28.360012,77.031527);
//var z=new google.maps.LatLng(28.360124,77.031429);
myTrip.push(new google.maps.LatLng(28.360012,77.031527));
myTrip.push(new google.maps.LatLng(28.360124,77.031429));
myTrip.push(new google.maps.LatLng(28.361024,77.034129));
var flightPath=new google.maps.Polyline({
path:myTrip,
strokeColor:"#0000FF",
strokeOpacity:0.8,
strokeWeight:2
});
flightPath.setMap(map);
google.maps.event.addDomListener(window, 'load', initialize);
这不是在地图上绘制折线。
有人可以帮帮我吗?
答案 0 :(得分:2)
您错过了initialize
功能:
function initialize() {
var mapProp = {
center: new google.maps.LatLng(28.360012, 77.031527),
zoom: 18,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var myTrip=new Array();
myTrip.push(new google.maps.LatLng(28.360012,77.031527));
myTrip.push(new google.maps.LatLng(28.360124,77.031429));
myTrip.push(new google.maps.LatLng(28.361024,77.034129));
var flightPath=new google.maps.Polyline({
path:myTrip,
strokeColor:"#0000FF",
strokeOpacity:0.8,
strokeWeight:2
});
flightPath.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);