从标记到折线。地图v3

时间:2011-08-15 07:32:56

标签: javascript google-maps-api-3 google-maps-markers

我有一个数组o标记,我想根据标题markers[i].title创建折线。我的大脑现在无法想到代码的正常和平,所以很少有帮助会有用......

1 个答案:

答案 0 :(得分:1)

您可能需要基于标记坐标(LatLng)的折线。这是一个模板代码:

function initialize() {
    var myOptions = {
      zoom: 4,
      center: new google.maps.LatLng(42.0, 10.0),
      mapTypeId: google.maps.MapTypeId.TERRAIN
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var points = [     
        new google.maps.LatLng(39.0, -3.0),     
        new google.maps.LatLng(52.1, 12.1),     
        new google.maps.LatLng(40.2, 32.7)  
    ]; 
    var markers = [];
    var path = [];
    for (var i = 0; i < points.length; ++i) {
        var marker = new google.maps.Marker({map: map, position: points[i]});
        markers.push(marker);
        path.push(marker.position);
    }
    var polyline = new google.maps.Polyline({     
        path: path,     
        strokeColor: "#FF0000"
    });    
    polyline.setMap(map);  
}