正如标题所说,我试图找到一种在iOS和Android Google Maps SDK上使用DirectionService的方法。我找到了几个关于类似解决方案的帖子;但是,我需要方向服务来获取多个航点,而不仅仅是两点之间的方向。 AFAIK,使用javascript api是唯一的方法...
我正在构建基于javascript api的离子应用,但我对移动设备上的地图性能不满意。
仅供参考,这是我在我的应用中需要的一段代码:
var request = {
origin: origin,
destination: destination,
waypoints: waypoints,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
optimizeWaypoints: document.getElementById('optimize').checked,
avoidHighways: document.getElementById('highways').checked,
avoidTolls: document.getElementById('tolls').checked
};
directionsService.route(request, function (response, status) {
if(status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
有关如何在iOS / Android中实现此功能的任何建议吗?
答案 0 :(得分:0)
If I am not wrong this is a hybrid app that would use Javascript to display the maps on cross platform (Android/iOS). You can directly make use of the direction service as you are already doing. For your specific questions related to the waypoints
, create an array where you store two attributes, location
and stopover
. This way you would have various waypoints in between the origin and destination.
{
origin: "Chicago, IL",
destination: "Los Angeles, CA",
waypoints: [
{
location:"Joplin, MO",
stopover:false
},{
location:"Oklahoma City, OK",
stopover:true
}],
provideRouteAlternatives: false,
travelMode: TravelMode.DRIVING,
unitSystem: UnitSystem.IMPERIAL
}
Please refer to the official Google documentation on Direction Service for Google Maps Javascript API