samedi 12 mai 2018

Generate new Lat/Lng between existing Lat/Lng provided by Google Maps Directions API

I am using the Google Maps Directions Service to request a path from a start point to an end point. This obviously returns a list of Lat/Lng markers which are joined to draw a path. The code looks like this:

  directionsService.route(request, function(result, status) {
    if (status == 'OK') {
      directionsDisplay.setDirections(result);
      var myRoute = result.routes[0].legs[0];
      //console.log(myRoute);

      for (var i = 0; i < myRoute.steps.length; i++) {
      var marker = new google.maps.Marker({
        position: myRoute.steps[i].start_point,
        map: map
      });
      console.log(myRoute.steps[i].start_point.lat(),myRoute.steps[i].start_point.lng() );
      attachInstructionText(marker, myRoute.steps[i].instructions);
      markerArray[i] = marker;
  }

    }
  });

enter image description here

I am having trouble figuring out an algorithm which will generate more Lat/Lng 'markers' between the existing ones.

To visualize this even further here is another diagram. Red X's show the points that the call returns. I have then added Blue X's on-top to show what I want the result to look like. enter image description here

Thanks!!!




Aucun commentaire:

Enregistrer un commentaire