简体   繁体   English

如何检查 LatLng 点是否位于 google maps android 上 geojson 层上的多边形内

[英]How to check if a LatLng point lies inside a polygon on the geojson layer on google maps android

Currently, I am working on a location-based project.目前,我正在从事一个基于位置的项目。 In this project I've added a GeoJsonLayer as below:在这个项目中,我添加了一个 GeoJsonLayer,如下所示: 在此处输入图像描述

As can be seen in the image, the red marker is inside a box.从图像中可以看出,红色标记位于一个框内。 Is there any way to check if the marker is inside a box (polygon) or not on google maps?有什么方法可以检查标记是否在框(多边形)内或不在谷歌地图上?

Inside the onMapReady() function I have added the GeoJson layer as follow: `在 onMapReady() 函数中,我添加了 GeoJson 层,如下所示:`

try {
    GeoJsonLayer layer = new GeoJsonLayer(mMap, R.raw.gokulpeth_area, MapsActivity.this);
    layer.getDefaultPolygonStyle().setStrokeColor(Color.WHITE);
    layer.addLayerToMap();
} catch (IOException | JSONException e) {
    e.printStackTrace();
}

` Please help me to achieve the task. ` 请帮助我完成任务。

You can use containsLocation(double latitude, double longitude, java.util.List<LatLng> polygon, boolean geodesic) method from Maps SDK for Android Utility Library :您可以使用Maps SDK for Android 实用程序库中的containsLocation(double latitude, double longitude, java.util.List<LatLng> polygon, boolean geodesic)方法:

public static boolean containsLocation(double latitude, double longitude, java.util.List polygon, boolean geodesic) public static boolean containsLocation(双纬度,双经度,java.util.List 多边形,布尔测地线)

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 ci rcle segments if geodesic is true, and of rhumb (loxodromic) segments otherwise.如果测地线为真,则多边形由大圆线段组成,否则由等向线(斜线)线段组成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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