Hi.

Here's abit of code i've used before to do this:

//      myPolyline is your polyline
//      mousePosition is the mouse position as a GLatLng
var length=myPolyline.getVertexCount(), distance, nearestDistance,
nearestIndex;
for(i=0; i<length; i++){
        distance=myPolyline.getVertex(i).distanceFrom(mousePosition);
        if(i===0){
                nearestDistance=distance;
                nearestIndex=i;
        } else if(nearestDistance>distance){
                nearestDistance=distance;
                nearestIndex=i;
        }
}

So the nearest polyline vertex to the mouse position is
myPolyline.getVertex(nearestIndex), and the distance betwen nearest
vertex and mouse position is nearestDistance.

Martin.


On 21 Sep, 16:43, RenĂ© <[email protected]> wrote:
> I've looked at a few libraries that help with this. SnapToRoute looks
> good, but I was wondering if anyone has come up with a simple, single
> function that quickly returns the nearest point index of a polyline
> when the mouse pointer gets near? Thanks.
>
> ...Rene

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to