简体   繁体   中英

Test if a point is in a polygon without the actual Polygon obj. Android Google Maps v2

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.

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM