我已将谷歌地图嵌入到我的页面中,并在其上显示各种标记。
每当用户点击标记时,就会在地图上绘制用户当前位置和标记之间的路线。
为了达到这个目的,我以下列方式使用google.maps.DirectionsService():
var directionService = new scp.google.maps.DirectionsService();
var requestDriving = {
| origin: start,
| destination: end,
| travelMode: scp.google.maps.TravelMode.DRIVING
};
directionService.route( requestDriving, function ( response, status ) {
| if ( status === 'OK' ) {
| | console.log( response );
| | scp.directionsDriving.setDirections( response );
| | scp.directionsDriving.setMap( scp.map );
| }
});
函数directionService.route(...)绘制上述点(制造者)之间的路径。
directionService.route回调中响应对象的内容如下:
Objectgeocoded_waypoints: Array[2]0: Object1: Objectlength: 2__proto__: Array[0]request: Objectdestination: Objectorigin: ObjecttravelMode: "WALKING"__proto__: Objectroutes: Array[1]0: Objectbounds: _.Icb: scf: xc__proto__: Objectcopyrights: "Картографски данни ©2017 Google"legs: Array[1]overview_path: Array[7]overview_polyline: "_tqcGo_lmCTBLCRKR[nA`AQl@"summary: "пл. „Народно събрание“ и ул. „Цар Шишман“"warnings: Array[1]waypoint_order: Array[0]__proto__: Objectlength: 1__proto__: Array[0]status: "OK"__proto__: Object
如何在用户绘制路线时创建显示/弹出的提示/链接,询问他/她是否要打开导航器(Android / OS /浏览器)以遵循路线上的指示绘制?
谢谢!
答案 0 :(得分:1)
我实际上找到了一个非常简单的解决方案。这可以通过谷歌地图网址来实现:
https://www.google.com/maps/dir/?api=1¶meters,
因为我使用的方便参数是标记的place_id:
https://www.google.com/maps/dir/?api=1&origin=[SOME PLACE]&origin_place_id=[SOME PLACE ID]&destination=[THE DESTINATION OF OUR ROUTE]&destination_place_id=[ANOTHER PLACE ID]