2013-10-10 29 views
0

我已經解決了在Google地圖中放置多個標記的問題。
現在我已經面臨這個標記之間繪製折線的問題。實際上,我是新的谷歌地圖API。的$lat1
my code:在多個標記之間繪製折線

價值
[["a, Ahmedabad, Gujarat 380001, India","23.0263517","72.5819013"],
["b, Ahmedabad, Gujarat, India","23.0690035","72.6801576"], ["c, Ahmedabad, Gujarat 380015, India","23.0171240","72.5330533"]]

<script type="text/javascript"> 
    var markerarray=new Array(); 
var locations = <?php echo json_encode($lat1);?>; 
var directionsService = new google.maps.DirectionsService(); 
var map = new google.maps.Map(document.getElementById('map'), { 
zoom: 10, 
center: new google.maps.LatLng(23.0171240, 72.5330533), 
mapTypeId: google.maps.MapTypeId.ROADMAP 
}); 

var infowindow = new google.maps.InfoWindow(); 

var marker, i; 
for (i = 0; i < locations.length; i++) 
{ 
    marker = new google.maps.Marker({ 
    position: new google.maps.LatLng(locations[i][1], locations[i][2]), 

    map: map 
    }); 

markerarray[i] = (Array(locations[i][1], locations[i][2])); 

    google.maps.event.addListener(marker, 'click', (function(marker, i) { 
    return function() { 
     infowindow.setContent(locations[i][0]); 
     infowindow.open(map, marker); 
    } 
    })(marker, i)); 
} 

var flightPath = new google.maps.Polyline({ 
    path: markerarray, 
    geodesic: true, 
    strokeColor: '#FF0000', 
    strokeOpacity: 1.0, 
    strokeWeight: 2 
}); 

flightPath.setMap(map); 
</script> 

我使用靜態value.but與動態值沒有成功繪製折線。
我使用這個例子繪製polyline.but我不知道如何使用它與多個標記。

Simple Polylines

在此先感謝。

+0

什麼是'$ lat1'價值? – davidkonrad

+0

我編輯我的排隊。 – DS9

回答

2

填充與位上的array並以此作爲arraypath -option爲google.maps.Polyline

+0

我更新了我的quetion.i使用標記位置填充數組,但不能將它與'google.maps.Polyline'一起使用。 – DS9

+0

您沒有使用標記位置(什麼是LatLng)填充它,您使用數組填充它,但路徑數組必須包含LatLng的:'markerarray [i] = marker.getPosition();' –

+0

謝謝非常。它已經解決了。還有一件事可以在標記之間繪製一條路線? – DS9

相關問題