Add point on polyline beetwen two existing points on click polyline event

1,763 views
Skip to first unread message

Dronnikkl

unread,
Aug 20, 2010, 9:04:59 AM8/20/10
to Google Maps JavaScript API v3
How can I add point on polyline beetwen two existing points on click
polyline event?
Thank you!

Nathan Raley

unread,
Aug 20, 2010, 10:01:39 AM8/20/10
to google-map...@googlegroups.com
Add a click event for your polyline and that will trigger when the user clicks on the polyline.

The click event returns a point (lat,lng).

Use this point to create a new marker there.

This would be the simplest method of which to do this.  If you are wanting to actually add the point to the MVC array of the polyline you will need to determine where to insert it into the Array.


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Dronnikkl

unread,
Aug 21, 2010, 5:49:17 AM8/21/10
to Google Maps JavaScript API v3
Thank you, I need to add the point to the MVC array. And I dont
understand how can i do it?

Dronnikkl

unread,
Aug 21, 2010, 8:02:35 PM8/21/10
to Google Maps JavaScript API v3
* how to determine where to insert it in array?

geoco...@gmail.com

unread,
Aug 21, 2010, 9:18:53 PM8/21/10
to Google Maps JavaScript API v3
On Aug 21, 5:02 pm, Dronnikkl <dronni...@gmail.com> wrote:
> * how to determine where to insert it in array?

I don't think it is particularly easy. It probably would be simplest
to add each segment separately to the map with its own click
listener. When a click happens on that polyline, you remove it from
the map and add two new ones, using the two original endpoints and the
clicked location.

The only other way is to determine which segment of the polyline it is
on by calculation. The use the MVC array insertAt to insert it:
http://code.google.com/apis/maps/documentation/javascript/reference.html#MVCArray


-- Larry

Joseph Elfelt

unread,
Aug 22, 2010, 10:22:20 AM8/22/10
to Google Maps JavaScript API v3
On Aug 21, 5:02 pm, Dronnikkl <dronni...@gmail.com> wrote:
> * how to determine where to insert it in array?

I have both a markers array and an MVC array.
The MVC array has the polyline going from marker to marker.

I assigned each element in the marker array a property which contains
the index value in the MVC array for the corresponding node.
Something like:
marker[i].mvc_index = j;

To insert a node into the MVC array after marker[i]:
path_var.insertAt(marker[i].mvc_index, position);

In other words, your code has to keep track of the relationship
between (1) markers and (2) nodes in the MVC array.

Larry is right. It does take a bit of work.

geoco...@gmail.com

unread,
Aug 22, 2010, 11:28:50 AM8/22/10
to Google Maps JavaScript API v3
Bill Chadwick's extension to the v2 API has a Bill Chadwick has a
Distance Point to Polyline function:
http://www.bdcc.co.uk/Gmaps/BdccGmapBits.htm
that actually calculates all the information you need.

http://www.geocodezip.com/v3_example_polylines_addpoint.html
(modified from one of Pil's examples on http://wolfpil.de since you
haven't provided an example of your map)

-- Larry
Reply all
Reply to author
Forward
0 new messages