2014-03-04 1 views
1

내지도에 폴리 라인 쇼를 만들 수없는 것 같습니다. setPath를 사용하고 변수에 위치 점을 추출합니다 : points. 지도에 다양한 폴리 라인을 표시하고 싶습니다. 모든 제안은 감사하겠습니다 :) 감사합니다! 코드의 당신의 다음 부분에서Google지도 api show polyline

var markers = []; 
var iterator = 0; 
var map; 
var mapCenter=new google.maps.LatLng(24.804188,54.862747); 

var points = [ 
['Airport', 24.433241, 54.651096, 12, '#airport'], 
['Marine Mall', 24.475968, 54.320953, 11, '#marinemall'], 
['Farrari World', 24.481739, 54.606426, 10, '#'], 
['Atlantis', 25.1299, 55.117924, 10, '#'], 
['Dubai Mall', 25.197126, 55.279092, 10, '#'], 
['Burj Khalifa', 25.197097, 55.274144, 10, '#'], 
['Burj Al Arab', 25.141167, 55.185472, 10, '#'], 
['Water Park', 25.134358, 55.120317, 10, '#'] 
]; 

function initialize() { 

var styles = [ 
    { 
    featureType: 'all', 
    elementType: 'label', 
    stylers: [ 
     { visibility:"off" } 
    ] 
} 
]; 

var mapOptions = { 
    center: mapCenter, 
    zoom:10, 
    mapTypeId:google.maps.MapTypeId.HYBRID 
}; 

map=new google.maps.Map(document.getElementById("map-canvas"),mapOptions); 
map.setOptions({styles:styles}); 

setPath(map, points); 
} 

function setPath(map, locations){ 
for (var i = 0; i < locations.length; i++) { 
    var place = locations[i]; 
    var myLatLng = new google.maps.LatLng(place[1], place[2]); 
    var line = new google.maps.Polyline({ 
     map: map, 
     geodesic: true, 
     path:myLatLng, 
     strokeColor:"#ED5552", 
     strokeOpacity:1, 
     strokeWeight:2 
    }); 
} 
} 
google.maps.event.addDomListener(window, 'load', initialize); 

답변

0

function setPath(map, locations) 
{ 
    for (var i = 0; i < locations.length; i++) 
    { 
     var place = locations[i]; 
     var myLatLng = new google.maps.LatLng(place[1], place[2]); 
     var line = new google.maps.Polyline({ 
      map: map, 
      geodesic: true, 
      path:myLatLng, 
      strokeColor:"#ED5552", 
      strokeOpacity:1, 
      strokeWeight:2 
     }); 
    } 
} 

당신은 배열 그것을 외부 루프를 정의 var line = new google.maps.Polyline({....이 아웃 사이드 루프

당신의 point/Location array에서 각 latlng를 밀어 만들 수 있도록 각 루프에서 myLatLng 변수를 생성

작동 중 Demo (변경 사항은

)
+0

도움을 많이 주셔서 감사합니다! 그것은 효과가있다! – christie

+0

환영합니다 !! 알게되어 기뻐 – Blu