从Google Maps API docs采取的行动(我加了注释,以澄清所发生的事情)
// initialize a mapOptions object
var mapOptions = {
zoom: 3,
center: new google.maps.LatLng(0, -180),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
// initialize a map object
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// initialize an array of LatLng objects. These are your markers in your city
var flightPlanCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)];
// initialize a Polyline object. You can set the color, width, opacity, etc.
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
// set the polyline's map with your map object from above.
flightPath.setMap(map);
听起来像是你要使用的[路线服务(https://developers.google.com/maps/documentation/的JavaScript /方向)。或者,您可能需要绘制大量[多段线](https://developers.google.com/maps/documentation/javascript/shapes#polylines) – duncan