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

标签 polygon android-maps geofencing android-geofence

我正在尝试使用多边形实现地理围栏系统。基本上,如果用户进入地理围栏区域,用户应该会收到通知。经过许多研究后,我只能使用 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 的每个多边形并将它们与此合并,它应该可以工作,不是吗?

关于polygon - 使用多边形形状创建和监控地理围栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53330452/

相关文章:

ios - 应用圆形区域的地理围栏时应用程序崩溃

language-agnostic - 如何在笛卡尔坐标中绘制n边正多边形?

polygon - openscad 差分多面体

android - ID、标签 null 或父 ID 与 com.google.android.gms.maps.MapFragment 的另一个 fragment 重复

android - 将 map 图钉添加到 Google Map Android 的最佳方式

android - 在 MapView 上绘制带有圆(半径)的叠加层

android - 使用 Fused location Geofences 时是否需要请求位置更新?

iOS 7 区域监控不可靠

java - 当坐标正确生成时,为什么我的代码没有生成多边形?

math - 针对矩形裁剪多边形