Erik Verboom
Erik Verboom

Reputation: 395

google maps api add a LatLng to the start of a polyline

I am using the google maps api to draw a gps track on a map. For this i am using a polyline overlay. So far, this works fine, but i would like to dynamically add and remove points from both sides of the polyline.

For removing points and adding points to the end of a polyline i know that i can use

google.maps.Polyline.getPath().removeAt(index);

and

google.maps.Polyline.getPath().push(LatLng);

Is there a function to add points to the start of a polyline easily? (similar to how one would use array.unshift(value) for adding an element to the start of an array)

Upvotes: 1

Views: 1848

Answers (1)

riddler
riddler

Reputation: 467

The path of a polyline is a MVCArray class which has array methods. https://developers.google.com/maps/documentation/javascript/3.exp/reference#MVCArray

Therefore you could use insertAt() insert a new point at index 0.

insertAt(0, item)

Upvotes: 4

Related Questions