-1

I have 2 latlong values. I need to show path between 3 latlong values. how to draw line between 2 markers. I need to show path between the markers so that we can know the movement

<script>

    function initMap() {
        var myLatLng = { lat: 17.446507, lng: 78.383033};
        var myLatLng1 = { lat: 17.428888, lng: 78.384444 }; 

        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 18,
            center: myLatLng,
        });
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 14,
            center: myLatLng1
        });


        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            title: 'Asset 1',
            animation: google.maps.Animation.DROP,

        });
        marker.addListener('click', toggleBounce);

        var marker = new google.maps.Marker({
            position: myLatLng1,
            map: map,
            title: 'Hello World!',
            icon:image
        });        
    }       
  }
</script>
Minal Chauhan
  • 6,025
  • 8
  • 21
  • 41
Krishna Mohan
  • 89
  • 3
  • 11
  • See examples in documentation. E.g. https://developers.google.com/maps/documentation/javascript/examples/directions-simple – xomena Mar 25 '17 at 12:08
  • possible duplicate of [how to draw a route between two markers in google maps](http://stackoverflow.com/questions/27341214/how-to-draw-a-route-between-two-markers-in-google-maps) – geocodezip Mar 25 '17 at 13:52

1 Answers1

0

You create a map object with center, and zoom, and then you overwrite it with a map object with different center and zoom, not sure why....

Just simply create a polyline with those coordinates ...

       var pathBetween = new google.maps.Polyline({
      path: [myLatLng,myLatLng1],
      strokeColor: '#FF0000',
      strokeOpacity: 1.0,
      strokeWeight: 2
    });

    pathBetween.setMap(map);

... and there should be a line displayed...

Marko Čepo
  • 185
  • 13
  • actually i was trying to capture 10 latest latlong values, show that it will look like object is moving one place to another. – Krishna Mohan Mar 25 '17 at 17:19
  • 1
    Ok, then this is more of a math problem ... in a nutshell ... you have a line with two points , divide that line in 10 equal pices and calculate the coordinates at each piece, and just create Markers with those 10 coordinates, here is a link to get you started .... https://www.nextgurukul.in/nganswers/ask-question/answer/Find-the-coordinates-of-points-dividing-the-line-segment-into-5-equal-parts/Coordinate-Geometry/92235.htm – Marko Čepo Mar 26 '17 at 11:56