F
F
freeeeez2018-03-30 11:07:54
JavaScript
freeeeez, 2018-03-30 11:07:54

How to get the coordinates of the marker when dragging it around the map?

When entering the departure and destination addresses, the map is initialized:

var directionsService = new google.maps.DirectionsService;
              var directionsDisplay = new google.maps.DirectionsRenderer({
                draggable: true});
              var map = new google.maps.Map(document.getElementById('map'), {
                zoom: 10,
                center: $('[name=from_address]').val()
              });
              directionsDisplay.setMap(map);
              directionsService.route({
                origin: $('[name=from_address]').val(),
                destination: $('[name=where_address]').val(),
                travelMode: 'DRIVING'
              }, function(response, status) {
                if (status === 'OK') {
                directionsDisplay.setDirections(response,{preserveViewport: true});
                } else {
                $('#map').html('<div class="ajax-error">Невозможно проложить автомобильный маршрут! Укажите другой адрес.</div>');
                }
              });


draggable: true makes it possible to move waypoints, but how to return the coordinates of the new point where the user moved it when moving? This is necessary in order to change the addresses in the from_address and where_address fields

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeeeez, 2018-03-30
@freeeeez

Everyone found this in the documentation, https://developers.google.com/maps/documentation/j...
issue closed

F
freeExec, 2018-03-30
@freeExec

Pick it up in a function with a new route result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question