2

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.

SoundsDangerous
  • 708
  • 6
  • 13

2 Answers2

1

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?

Community
  • 1
  • 1
Selecsosi
  • 1,636
  • 19
  • 23
0

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.

SoundsDangerous
  • 708
  • 6
  • 13