Reputation: 738
How do we test if a lat/long point is in a polygon without actually adding it to the map? This version seems to only return the polygon obj after adding it to the map. I only want to draw the polygon if a point is contained within it.
Upvotes: 2
Views: 816
Reputation: 738
Having spent quite a bit with this api since my question, I figured I should post a decent quick solution I had discovered. You can create a PolyOptions object that will contain the List of LatLng objects. With the List you can create a LatLngBounds object. With the LatLngBounds object you can call .contains() passing in your LatLng point which will return the boolean you are looking for.
Upvotes: 0
Reputation: 1646
Kind of cheap option, but can you map the points of the polygon to a project of screen coordinates using the api GoogleMaps call toScreenLocation() for each point, then do the same for the point you want to test. Form the polygon points into a polygon and test for the the intersection using something like https://stackoverflow.com/a/15817043/418505?
Upvotes: 1