polygon - 使用多边形形状创建和监控地理围栏

我正在尝试使用多边形实现地理围栏系统。基本上,如果用户进入地理围栏区域,用户应该会收到通知。经过许多研究后,我只能使用 Circular 找到 Geofence。到目前为止,我实现了该系统,但它仅通过圆形进行监视,而不是有人进入 map 中绘制的多边形。如果有人以前做过 Polygon Geonfencing,请帮助我

这是我用来绘制多边形的代码

    private void drawGeofence() {
    Log.d(TAG, "drawGeofence()");

    polyLatLng = new ArrayList<>(  );
    polyLatLng.add( new LatLng( 6.895450, 79.852170 ) ); // Should match last point
    polyLatLng.add( new LatLng(6.897287, 79.859544));
    polyLatLng.add( new LatLng( 6.905271, 79.862609 ) );
    polyLatLng.add( new LatLng( 6.906114, 79.858998 ) );
    polyLatLng.add( new LatLng( 6.911808, 79.856206 ) );
    polyLatLng.add( new LatLng( 6.912200, 79.851381 ) );
    polyLatLng.add( new LatLng( 6.911627, 79.849621 ) );
    polyLatLng.add( new LatLng( 6.910965, 79.848073 ) );
    polyLatLng.add( new LatLng( 6.895450, 79.852170 ) );              // Should match first point

    Log.i(TAG, "computeArea " + SphericalUtil.computeArea(polyLatLng));

    map.addPolygon(new PolygonOptions()
            .addAll(polyLatLng)
            .strokeColor(Color.BLACK)
            .strokeWidth( 4 )
            .fillColor(0x220000FF));
}

这是我的地理围栏代码,它只在圆形区域进行跟踪

 private static final float GEOFENCE_RADIUS = 1006.3975694699f; // in meters
private void startGeofence() {
    Log.i(TAG, "startGeofence()");
    if( geoFenceMarker != null ) {

        // create geofence
        Geofence geofence = createGeofence( 6.904254, 79.853798, GEOFENCE_RADIUS );
        GeofencingRequest geofenceRequest = createGeofenceRequest( geofence );
        addGeofence( geofenceRequest );
    } else {
        Log.e(TAG, "Geofence marker is null");
    }
}

// Create a Geofence
private Geofence createGeofence( double lat, double lng, float radius ) {
    Log.d(TAG, "createGeofence");

    return new Geofence.Builder()
            .setRequestId(GEOFENCE_REQ_ID)
            .setCircularRegion( lat, lng, radius)
            .setExpirationDuration( GEO_DURATION )
            .setTransitionTypes( Geofence.GEOFENCE_TRANSITION_ENTER
                    | Geofence.GEOFENCE_TRANSITION_EXIT )
            .build();
}enter code here

最佳答案

你能使用 geopandas 中的这个函数吗:https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.union.html 如果您隔离 Multipolygon 的每个多边形并将它们与此合并,它应该可以工作,不是吗?

https://stackoverflow.com/questions/53330452/

相关文章:

c# - 如何在对数据库进行外部更改后更新/同步 DbContext

laravel - 为什么 Vue.js 在 Laravel 5.6 中不显示任何内容?

oracle - 在 Oracle SQL Insert 语句中返回自动增量值?

python - 尝试使用 Cloud TPU 恢复更新的 BERT 模型检查点时出现 Infeed

reactjs - 当 url 具有参数时,未应用 React Nav Link activeSty

lua - 如何在 luacheck 中将警告设为错误?

c# - 如何自定义渲染 UWP 湿墨

angular - AWS Amplify 和 Angular 7 的 AOT 运行时错误 - AP

python - PyAudio stream.is_active(),它是如何知道自己是否活跃的

reactjs - 明确停止订阅