Check if point is in polygon with Google Maps API in Android

浪尽此生 提交于 2019-12-01 06:50:12
antonio

You can use the PolyUtil.containsLocation method from the Google Maps Android API Utility Library. From the documentation:

public static boolean containsLocation(LatLng point, java.util.List polygon, boolean geodesic)

Computes whether the given point lies inside the specified polygon. The polygon is always considered closed, regardless of whether the last point equals the first or not. Inside is defined as not containing the South Pole -- the South Pole is always outside. The polygon is formed of great circle segments if geodesic is true, and of rhumb (loxodromic) segments otherwise.

A bit later response, but for future searches, you can also check if a location is inside the current visible map area by using:

// Kotlin code
var location = LatLng(-27.6016488, -48.5137219)    
val isInside = mGoogleMap.projection.visibleRegion.latLngBounds.contains(location)

Documentation link: contains (LatLng point)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!