Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Google Maps API V3, determine if a marker is inside a KML Layer boundary

Is there a way to determine if a marker has entered an area covered by a KmlLayer? My .kml is mostly made up of a <Polygon> with a bunch of coordinates that define the boundary.

There is an article I found that describes some similar to what I'm looking for, created using an overlay: http://www.paulmcilwaine.com/api/google-maps-detecting-markers-in-a-particular-boundary

That method has the advantage of using getBounds(), but I am looking for a way to do this with a KmlLayer boundary. KmlLayer doesn't seem to have a handy function like getBounds(), but I do have all the coordinates available to me in the KML file itself, so I'm thinking there's a way to create my own getBounds() function. I just need a way to determine if a marker (or a latlang) is inside those coordinates in the KML file.

Thanks for any ideas!

like image 255
Sean Fahey Avatar asked Apr 25 '12 20:04

Sean Fahey


1 Answers

There is no such function on KmlLayer. However, if you can extract the polygon boundaries, and create a polygon you can use the Geometry library of the Maps API to determine if the point lies inside the polygon: https://developers.google.com/maps/documentation/javascript/reference#poly

like image 176
Mano Marks Avatar answered Oct 02 '22 09:10

Mano Marks