Reputation: 167
I have embedded google maps into my page, displaying on it various markers.
Whenever the user clicks on a marker, a route is drawn on the map between the user's current location and the marker.
In order to achieve this, I use google.maps.DirectionsService() in the following manner:
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 );
| }
});
The function directionService.route (...) draws the route between the above-mentioned points(makers).
The content of the response object in the callback of directionService.route is the following:
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
How can I create a prompt/link to appear/pop up whenever the user has drawn a route, asking him if he/she would like to open the navigator (Android/OS/Browser) to follow the directions along the route drawn?
Thanks!
Upvotes: 0
Views: 259
Reputation: 167
I've actually found a quite simple solution.This can be achieved using google maps urls:
https://www.google.com/maps/dir/?api=1¶meters,
as the convenient params here I used were the place_id's of the markers:
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]
Upvotes: 1