0
我已經嵌入谷歌地圖到我的頁面,顯示它的各種標記。如何提示將Google地圖路線從嵌入地圖打開到Google地圖導航器中?
只要用戶點擊標記,就會在地圖上繪製用戶當前位置和標記之間的路線。
爲了實現這一點,我以下面的方式使用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`[email protected]"summary: "пл. „Народно събрание「 и ул. „Цар Шишман「"warnings: Array[1]waypoint_order: Array[0]__proto__: Objectlength: 1__proto__: Array[0]status: "OK"__proto__: Object
如何創建一個提示/鏈接出現/彈出每當用戶繪製的路徑,詢問如果他/她想打開導航器(Android/OS /瀏覽器)以遵循所繪製路線的指示,他是否願意?
謝謝!