Allow user to add directions on map (google map API)

I know that you can programmatically add markers for directions on a map. But how do you allow the user to do this? Like on Google maps, you just right-click and then click "directions from / to here" and a marker is added. This functionality is apparently missing from the API.

EDIT: Perhaps I was not clear enough. I am not talking about API functions. I just want the user to be able to get the route menu that you get when you right-click . Take a look at google maps for reference.

+3
source share
1 answer

There is nothing in the API to show the "Directions from here" and "Directions here" context menus; you will need to create this functionality yourself.

You can handle the * rightclick * event on the map object to get clicks on the context (and its associated location), and then go through the locations in the Directions Service .

NB It is currently recommended that you use the version 3 API for Google Maps (Directions Service) rather than the version 2 API proposed in the previous answer (GDirections).

+4
source

Source: https://habr.com/ru/post/1737029/


All Articles