Search code examples
androidgoogle-mapsnavigationgeolocationandroid-gps

Changing destination coordinates at runtime (Dynamically)


I want to program an Android application where user A can navigate it self to user B (using Google Maps and their Navigator). But I want my android application to update the coordinates of user B and send it to user A in real time.

My question is: Are there any way for user A to retrieve the updated coordinates AND not getting a new route calculated every time that user B change its position?

Since I want my user B to send new coordinates every 15 meters, it would be hell if user A gets a new route calculated every time.


Solution

  • You can use setDirection() method on the renderer and pass it to DirectionsResult. The DirectionsResult contains the result of the directions query, which you may either handle yourself which can automatically handle displaying the result on a map. The renderer is an MVCObject, it will automatically detect any changes to its properties and update the map when its associated directions have changed.

    The following example calculates directions between two locations on Route, where the origin and destination are set by the given "start" and "end" values in the dropdown lists. The DirectionsRenderer handles display of the polyline between the indicated locations, and the placement of markers at the origin, destination and any waypoints, if applicable.

    function calcRoute() {
      var start = document.getElementById('start').value;
      var end = document.getElementById('end').value;
      var request = {
        origin: start,
        destination: end,
        travelMode: 'DRIVING'
      };
      directionsService.route(request, function(result, status) {
        if (status == 'OK') {
          directionsDisplay.setDirections(result);
        }
      });