我正在尝试使用Google Maps v3 绘制n点(lat,lan)之间的路线.要做到这一点,我正在使用DirectionsService
它为我提供了一条路线,然后我将这些坐标推入a MVCArray
然后通过使用a绘制该路径Polyline
.
HTML:
<div id='map'></div>
Run Code Online (Sandbox Code Playgroud)
CSS:
#map{
width:400px;
height:400px;
}
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
$(function () {
//The list of points to be connected
var markers = [
{
"title": 'Duero',
"lat": '40.480243',
"lng": '-3.866172',
"description": '1'
},
{
"title": 'Reyes Catolicos',
"lat": '40.477997',
"lng": '-3.870865',
"description": '2'
},
{
"title": 'Guadarrama',
"lat": '40.478998',
"lng": '-3.878755',
"description": '3'
}
];
var map;
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, …
Run Code Online (Sandbox Code Playgroud)