I'm trying to understand if a given point (Latitude, Longitude) stays inside a GeoJsonLayer. I've written this function but I don't have a bounding box for the layer so it's not working:
private fun isInsideLayer(userLatitude: Double, userLongitude: Double, layer: GeoJsonLayer): Boolean {
val position = LatLng(userLatitude, userLongitude)
return layer.boundingBox.contains(position)
}
Below there's my JSON source.
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
13.36761474609375,
52.626602989514865
],
[
13.379974365234373,
52.616181784632865
],
[
13.380317687988281,
52.606175093642754
],
[
13.36761474609375,
52.626602989514865
]
]
]
}
}
Anybody has a clue? Thanks
this is quite a theoretical question, unless knowing which kind of geometries are present - because a geometry is not necessarily a polygon, which could contain a point. else one could only check if a point matches exactly. the fundamental problem is that .getBoundingBox()
returns a rectangle - and not a polygon, which does not permit proper matching due to the surrounding excess area.
eg. in order to construct a polygon there would be (at least) 3 geometries of type point required.
or (at least) 1 geometry of type polygon... which could be matched with Utility Library's PolyUtil:
PolyUtil.containsLocation(position)
there are overall 10 different geometry objects for a feature object, which would need to be considered... is what RFC 7946 hints for.