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

后端 未结 2 794
我在风中等你
我在风中等你 2021-01-05 03:52

I am using the Google Maps API on Android to create a puzzle. This link contains the data I used to draw African countries: World countries coordinates.

When the use

相关标签:
2条回答
  • 2021-01-05 04:10

    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)

    0 讨论(0)
  • 2021-01-05 04:26

    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.

    0 讨论(0)
提交回复
热议问题