本文介绍了如何使用红宝石获得两个坐标之间的汽车路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Google地图和汽车路线开发Rails应用.
I'm developing rails app with google maps and car routes.
我有汽车路线的起点和终点-两个坐标.如何获得完整的汽车路线(通过街道的汽车坐标数组)?我可以使用gmaps4rails
和geocoder
进行操作吗?
I have a start and finish points for car route - two coordinates. How can I get a full car route (array of coordinates for car through streets)? Can I do it using gmaps4rails
and geocoder
?
类似这样的东西:
start_point = [41,2423; 45,323452]
end_point = [42,2423; 42,323452]
full_route = some_method_for_calculate_route( start_point, end_point )
#paint line on map from array of points
paint_line( full_route )
请帮助,谢谢:)
推荐答案
如果要在客户端执行此操作,则可以使用在这里放屁.
If you want to do it client side, you have a plunkr here.
它受到此处的Google文档的启发.
基本上是与Google图书馆互动的一种方式
Basically its a way to interact with google libraries
var handler = Gmaps.build('Google');
handler.buildMap({ internal: {id: 'map'}}, function(){
var start_point = [43.2423, 5.323452];
var end_point = [44.2423, 5.323452];
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(handler.getMap());
var request = {
origin: new google.maps.LatLng(start_point[0], start_point[1]),
destination: new google.maps.LatLng(end_point[0], end_point[1]),
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
});
这篇关于如何使用红宝石获得两个坐标之间的汽车路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!