在Google Maps v3中,可以使用Polyline API来创建多个路线。Polyline是一种在地图上绘制线条的方法,可以用来表示道路、航线或其他路径。要在Google Maps v3上创建多个路线,可以使用以下步骤:
<!DOCTYPE html>
<html>
<head>
<title>Google Maps</title>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>
<script src="main.js"></script>
</head>
<body onload="initMap()">
<div id="map" style="width: 100%; height: 100%"></div>
</body>
</html>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: { lat: 40.730610, lng: -73.935242 }
});
}
function createPolyline(map, path) {
var polyline = new google.maps.Polyline({
path: path,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
polyline.setMap(map);
}
var routes = [
[
{ lat: 40.730610, lng: -73.935242 },
{ lat: 40.745213, lng: -73.985242 }
],
[
{ lat: 40.710610, lng: -73.935242 },
{ lat: 40.725213, lng: -73.985242 }
]
];
for (var i = 0; i< routes.length; i++) {
createPolyline(map, routes[i]);
}
这样,就可以在Google Maps v3上创建多个路线了。注意,在实际应用中,需要根据具体需求来定义路线和坐标。
领取专属 10元无门槛券
手把手带您无忧上云