2013-07-27 2 views
0

여기에 Json 객체로 응답하는 마커가 있고이 마커가 Google지도에 표시됩니다. 여기 나는이 마커 사이의 경로를 그리기를 원하지만 firebug는 (value.Latitude)의 잘못된 값을 표시합니다. 여기에 값은 내 JSON 개체입니다.json 데이터에서 Google지도의 경로 표시

var request = { 
        origin:value.Latitude, 
        destination:value.Longitude, 
        travelMode: google.maps.DirectionsTravelMode.DRIVING 
       }; 

여기 value.Latitude는 단일 번호 내 전체 스크립트

<script type="text/javascript" 
    src="http://maps.google.com/maps/api/js?sensor=false"> 
</script> 

<style type="text/css"> 
    #map_canvas { 
    height: 500px; 
    width: 800px; 
    position: static; 
    top: 0px; 
    left: 100px; 
} 
</style> 



<script> 
     var directionDisplay; 
     var directionsService = new google.maps.DirectionsService(); 

    function initialize() { 
var latlng = new google.maps.LatLng(18.5236, 73.8478); 
directionsDisplay = new google.maps.DirectionsRenderer(); 

var myOptions = { 
    zoom: 8, 
    center: latlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP, 
    streetViewControl: false, 
    mapTypeControl: false 
}; 

    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     myOptions); 
    directionsDisplay.setMap(map); 

$(document).ready(function() { 
    $("#btnSubmit").click(function() { 
     var Source = $("#Source").val(); 
     var Destination = $("#Destination").val(); 
     authenticate(Source, Destination); 
    }); 
}); 

function authenticate(Source,Destination) { 
    $('#somediv').empty(); 

    var table = $('<table/>').appendTo($('#somediv')); 
    $.ajax 
    ({ 
     type: 'GET', 
     url: 'REST/WebService/GetLogin', 
     dataType: 'json', 
     data:{'Source': Source, 'Destination': Destination }, 

     error:function() 
     { 
      alert("unsuccessfull"); 
     }, 
     success:function(feeds) 
     { 
      alert(feeds.length); 

      $.each(feeds, function (index, value) { 

       new google.maps.Marker({ 
         position: new google.maps.LatLng(value.Latitude,value.Longitude), 
         map: map, 
         title: "Marker Placing" 
       }); 

       var request = { 
        origin:value.Latitude, 
        destination:value.Longitude, 
        travelMode: google.maps.DirectionsTravelMode.DRIVING 
       }; 

       directionsService.route(request, function(response, status) { 
        if (status == google.maps.DirectionsStatus.OK) { 
         directionsDisplay.setDirections(response); 
        } 
       }); 
      }); 
       //alert(feeds.toSource()); 
     } 

    }); 
    } 
} 
</script> 
+0

무엇 기원 '의 값 : value.Latitude'와'대상 : value.Longitude'? 이름과 google.maps.Marker를 만드는 데 사용하는 방법에 따라 길 찾기 요청이 잘못된 것으로 보입니다. 번호가 아니라 주소 문자열 또는 google.maps.LatLng 개체 여야합니다. – geocodezip

답변

0

showing error invalid value of (value.Latitude).

입니다. DirectionsService 요청에이를 전달하려면 google.maps.LatLng 객체 (생성자에 대해 2 개의 숫자 인수가 사용됨) 또는 지오 코딩 될 수있는 주소 인 문자열로 변환되어야합니다.

From the documentation :

origin  | LatLng|string | Location of origin. This can be specified as either a string to be geocoded or a LatLng. Required. 
destination | LatLng|string | Location of destination. This can be specified as either a string to be geocoded or a LatLng. Required. 
+0

그래서 어떻게 할 수 있습니까? 나는 무작위로 물건을 시험하고 있었기 때문에 나는 여기에 붙어있다. – shanky

+0

원본 및 대상 좌표 란 무엇입니까? 나는 하나의 마커/좌표 세트만을 보았습니다. 그들과 함께 google.maps.LatLng 개체를 만들고 DirectionsRequest에 전달합니다. – geocodezip

+0

원본 및 대상 좌표는 위도 및 경도 값의 형태로 JSON 개체입니다. 어디에서나 문자열로 시작하고 끝나는 것을 볼 수 있습니다. 위도와 경도 값을 원하면 어떻게 될까요? 나는 이것을 어떻게 변환하여 google.maps.LatLng()에 전달할 수 있을지 모르겠다. – shanky