2014-02-22 22 views
0

我已經研究了很多來源,並且在gmaps4rails的v2中找不到任何幫助。我想要以文本格式(逐步列表)獲取路線,或者只顯示我自己的地圖上的路線。我希望我的出發點是經濟和經濟,而且目的地也是經濟和經濟。感謝您的任何幫助表示讚賞。如何獲取gmaps4rails v2中的路線?

回答

3

這是非常簡單的from google example here

var directionsDisplay = new google.maps.DirectionsRenderer(); 
var directionsService = new google.maps.DirectionsService(); 

function calcRoute() { 
    var origin  = new google.maps.LatLng(41.850033, -87.6500523); 
    var destination = new google.maps.LatLng(42.850033, -85.6500523); 
    var request = { 
     origin:  origin, 
     destination: destination, 
     travelMode: google.maps.TravelMode.DRIVING 
    }; 
    directionsService.route(request, function(response, status) { 
    if (status == google.maps.DirectionsStatus.OK) { 
     directionsDisplay.setDirections(response); 
    } 
    }); 
} 

calcRoute(); // call this anywhere you want 

var handler = Gmaps.build('Google'); 
handler.buildMap({ internal: {id: 'map'}}, function(){ 
    directionsDisplay.setMap(handler.getMap()); 
}); 
+1

謝謝這就是我一直在尋找 – ominousbit

+0

請學會接受的答案,它很容易:http://meta.stackexchange.com/questions/5234/how-接受答案的工作 – apneadiving

+0

嗨,apneadiving,我有多個目的地。你能告訴我如何顯示多個目的地的路線嗎?例如:我想顯示最近的機場,巴士站和火車站搜索的位置。使用上述代碼,我可以顯示機場,公交車站或火車站的路線。但我想要顯示所有這些路線 –