get polyline point index

954 views
Skip to first unread message

massimo bastianon

unread,
Dec 28, 2011, 5:22:50 AM12/28/11
to Google Maps JavaScript API v3
I attached the polyline mouseover event, but the event.latLng returned
is different than any polyline point..

Is there a way to get index of a point inside a polyline?

a sample here: http://www.pedemontanadelgrappa.it/fu.html
Move the mouse over the polyline. Alert is on line 130.

Marcelo

unread,
Dec 28, 2011, 11:35:46 AM12/28/11
to Google Maps JavaScript API v3
On Dec 28, 3:22 am, massimo bastianon <bastian...@gmail.com> wrote:
>
> Is there a way to get index of a point inside a polyline?
>

A polyline, (for example of a single straight line), has only two
points in its path array, (the two end points). Everything in between
is calculated, and there is an infinite number of points between the
mouse and the line and between the two end points. You'd have to be
very lucky to hit exactly the lat/lon of an end point.
What you might need to do is to calculate the distance to the nearest
point with a threshold, like this V2 example:
http://maps.forum.nu/gm_mouse_dist_to_line.html

--
Marcelo - http://maps.forum.nu
--

Marcelo

unread,
Dec 28, 2011, 11:44:52 AM12/28/11
to Google Maps JavaScript API v3
Here's another example (V3):
http://maps.forum.nu/v3/gm_directions.html

Get directions and then move the mouse over the elevation chart.
This is using an array, (internal to the chart), to hold the points of
the polyline. You could do something similar by finding the nearest
point in the MVCArray returned by Polyline.getPath()

--
Marcelo - http://maps.forum.nu
--



On Dec 28, 9:35 am, Marcelo <marcelo...@hotmail.com> wrote:
> On Dec 28, 3:22 am, massimo bastianon <bastian...@gmail.com> wrote:
>
>
>
> > Is there a way to get index of a point inside a polyline?
>
> A polyline, (for example of a single straight line), has only two
> points in its path array, (the two end points). Everything in between
> is calculated, and there is an infinite number of points between the
> mouse and the line and between the two end points. You'd have to be
> very lucky to hit exactly the lat/lon of an end point.
> What you might need to do is to calculate the distance to the nearest
> point with a threshold, like this V2 example:http://maps.forum.nu/gm_mouse_dist_to_line.html
>
> --
> Marcelo -http://maps.forum.nu

sb

unread,
Dec 28, 2011, 4:58:57 PM12/28/11
to Google Maps JavaScript API v3
This example has a click event. Easy to change to a mouseover.
http://srsz750b.appspot.com/api3/polylines-multiple.html

massimo bastianon

unread,
Dec 29, 2011, 2:54:26 AM12/29/11
to Google Maps JavaScript API v3
I thought there was an easiest way...
Finding the closest point in quite simple but could become very heavy
for the browser if I have more than 500 points

On 28 Dic, 22:58, sb <shaneb...@gmail.com> wrote:
> This example has a click event. Easy to change to a mouseover.http://srsz750b.appspot.com/api3/polylines-multiple.html
Reply all
Reply to author
Forward
0 new messages