2013-06-21 42 views
0

使用Google Maps API v3顯示從用戶定義的起點到我的屬性的路線。使用Google Maps API的Long/Lat指示的準確性

除了終點的準確性,這在技術上是正常的。我已經將我的房產的Long/Lat定義爲確切點,但方向仍然會將您帶到大約100米外的一條街道。

有沒有一種方法可以強制指示將您帶到一個確切點?

這裏是我的代碼的情況下,它可以幫助...

function getDirections(x, y) { 

      $("#directionsPanel").html(""); 
      var directionsService = new google.maps.DirectionsService(); 
      var directionsDisplay = new google.maps.DirectionsRenderer(); 

      var myOptions = { 
       zoom: 10, 
       mapTypeId: google.maps.MapTypeId.ROADMAP, 
       scrollwheel: false 
      } 

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

      var request = { 
       origin: x, 
       destination: $('.lat').text() + ',' + $('.lng').text() , 
       travelMode: google.maps.DirectionsTravelMode.DRIVING, 
       unitSystem: google.maps.UnitSystem.IMPERIAL, 
       provideRouteAlternatives: true, 
       region: "GB" 
      }; 

      directionsService.route(request, function (response, status) { 

        directionsDisplay.setDirections(response); 
        $(".noValidRoute").hide(); 

      }); 

     } 
+0

您的'travelMode'正在駕駛中。 –

+0

是的,但是爲什麼方向在道路上甚至附近的道路上停留幾百碼? – Tom

回答

1

假設在getDirections(x, y)x,y你只使用x了你的財產的座標。

TRY ;

function getDirections(x, y) { 

     var origin = new google.maps.LatLng(x,y) 
     $("#directionsPanel").html(""); 
     var directionsService = new google.maps.DirectionsService(); 
     var directionsDisplay = new google.maps.DirectionsRenderer(); 

     var myOptions = { 
      zoom: 10, 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
      scrollwheel: false 
     } 

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

     var request = { 
      origin: origin, 
      destination: $('.lat').text() + ',' + $('.lng').text() , 
      travelMode: google.maps.DirectionsTravelMode.DRIVING, 
      unitSystem: google.maps.UnitSystem.IMPERIAL, 
      provideRouteAlternatives: true, 
      region: "GB" 
     }; 

     directionsService.route(request, function (response, status) { 

       directionsDisplay.setDirections(response); 
       $(".noValidRoute").hide(); 

     }); 

    }