superGokuN
superGokuN

Reputation: 1424

Google map Draggable PolyLines

I am having a map with some polylines with the distance [api v3]. I want that when someone drag the polyline at the same time the distance also get updated but dont know how to do. Please help me, any good tutorial or another threads are most welcome

Thanks for helping me

Naveen

Upvotes: 2

Views: 2183

Answers (2)

superGokuN
superGokuN

Reputation: 1424

There is a attribute which makes your polyline editable.

polyPath.setEditable(true);

Now use a listener to check the editing.

   google.maps.event.addListener(polyPath, 'capturing_changed', function() {

    var array = polyPath.getPath(); //getPath() gives u array of current markers latlng over map 

                    var tempDistance = 0;

                    var tempPathArray = [];

                     for(i = 0; i < array.length; i++){

                       tempPathArray.push(array.getAt(i));

                      }


                       for(k = 1; k < tempPathArray.length; k++)

                       {


  var calculateNewDistance=google.maps.geometry.spherical.computeDistanceBetween(tempPathArray[k-1],tempPathArray[k]);

                            tempDistance += calculateNewDistance;

                        }
   }

// make sure to add the following script to compute the distance between two latlngs

Upvotes: 0

Heitor Chang
Heitor Chang

Reputation: 6057

This page describes using draggable markers and updating the distance when a marker is moved.

http://exploregooglemaps.blogspot.com.br/2012/02/measuring-distance-with-markers.html

Upvotes: 1

Related Questions