2017-10-31 1 views
-2

I 같은 배열을 구비하고있는 폴리 GoogleMap으로의 경로로하는 방법이 [17.4172192,78.401285,17.418407,78.401629,17.41809,78.40061,17.417865,78.398234,17.405446,78.404805, 난 전달할 이 JSONArray는 Google지도의 폴리 라인 경로에 동적으로 배치됩니다. 내가 그것을 잘 작동했다 정적으로 위도와 경도를 통과하면 ,하지만 동적으로 내가 그것을 여기에, 저를 도와주세요 작동하지 않는 루프를 실행 한 내 request.getAttribute ("latlongjson")에서 자바 스크립트, 입니다 나는 값이 [17.4172192,78.401285,17.418407,78.401629,17.41809,78.40061,17.417865,78.398234,17.405446,78.404805]는 passlatitude 경도 값 동적 자바 스크립트

<script> 
      var poly; 
     var map; 
     var locations = <%= request.getAttribute("latlongjson") %> ; 

     function initMap() { 
     map = new google.maps.Map(document.getElementById('map'), { 
      zoom: 15, 
      center: {lat: 17.4172192, lng: 78.401285} 
     }); 

     // for polyline 
for (var i = 0, ln = locations.length; i < ln; i += 2) { 
      poly = new google.maps.Polyline({ 
      path:[ 
       new google.maps.LatLng(latitide[i],latitude[i+1]) 
      ], 
      strokeColor: '#0000FF', 
      strokeOpacity: 1.0, 
      strokeWeight: 3, 
     }); 
    } 

     poly.setMap(map); 
    // google.maps.event.addDomListener(window, 'load', initialize); 

     } 

     } 
    </script> 

누구나 사전에 나에게

+0

당신이 누락을 감사 도와주세요하는 데 세미 콜론? var locations = <% = request.getAttribute ("latlongjson") %>; –

+0

나중에이 문제는 아니지만이 논리를 사용하는 마커에서 작동하지만 폴리 라인 (var i = 0, ln = locations.length; i Naveen

+0

whate는 console.log (locations)를 반환합니까? –

답변

0
<script> 

     var poly; 
     var map; 
     var locations = [ 
      17.4172192,78.401285, 
      17.418407, 78.401629, 
      17.418090, 78.400610, 
      17.417865, 78.398234 
      ]; 
    // var locations = <%= request.getAttribute("latlongjson") %> 

     // for center the map 

     function initMap() { 
     map = new google.maps.Map(document.getElementById('map'), { 
      zoom: 15, 
      center: {lat: 17.4172192, lng: 78.401285} // Center the map on Chicago, USA. 
     }); 


var flightPlanCoordinates = new Array(); 
for(i=0;i<locations.length;i += 2) 
{ 
    var point =new google.maps.LatLng(locations[i],locations[i+1]); 
    flightPlanCoordinates.push(point); 
} 
alert(flightPlanCoordinates); 


     // for polyline 

     poly = new google.maps.Polyline({ 
     /* path:[ 
       new google.maps.LatLng(17.4172192,78.401285), 
       new google.maps.LatLng(17.418407, 78.401629), 
       new google.maps.LatLng(17.418090, 78.400610), 
       new google.maps.LatLng(17.417865, 78.398234) 
      ], */ 
      path : flightPlanCoordinates, 
      // geodesic: true, 
      strokeColor: '#0000FF', 
      strokeOpacity: 1.0, 
      strokeWeight: 3, 
     }); 

     // for markers 

     for (var i = 0, ln = locations.length; i < ln; i += 2) { 
      var marker = new google.maps.Marker({ 
       position: new google.maps.LatLng(locations[i], locations[i + 1]), 
       map: map, 
       title: locations[i]+", "+locations[i+1], 
      }); 
     } 
     poly.setMap(map); 
    // google.maps.event.addDomListener(window, 'load', initialize); 
     // Add a listener for the click event 
     map.addListener('click', addLatLng); 
     } 
} 
</script>