【问题标题】:remove triggered geofence after transition转换后删除触发的地理围栏
【发布时间】:2015-07-28 13:46:52
【问题描述】:

我正在尝试在输入地理围栏后删除它,以阻止它重新触发输入转换。从一个类似的问题中,我得到了这条运行良好的线路

LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient,getGeofencePendingIntent()).setResultCallback(this);

但是,它会删除所有地理围栏,而不仅仅是已触发的地理围栏。

我需要做什么才能选择要删除的正确 ID?

【问题讨论】:

    标签: android transition android-geofence


    【解决方案1】:

    您需要传递用于构建地理围栏的相同字符串。

    String geofenceId = "randomId";
    Geofence geofence = new Geofence.Builder()
        .setRequestId(geofenceId)
        ....
        .build();
    
    GeofencingRequest request = new GeofencingRequest.Builder()
        .addGeofence(geofence)
        ....
        .build();
    
    LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, request, pendingIntent);
    

    要移除地理围栏,您可以使用

    List<String> geofencesToRemove = new ArrayList<>();
    geofencesToRemove.add(geofenceId);
    LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, geofencesToRemove);
    

    或者您可以从收到的 Intent 中获取地理围栏。

    GeofencingEvent event = GeofencingEvent.fromIntent( intent_you_got_from_geofence );
    List<Geofence> triggeredGeofences = event.getTriggeringGeofences();
    List<String> toRemove = new ArrayList<>();
    for (Geofence geofence : triggeredGeofences) {
        toRemove.add(geofence.getRequestId());
    }
    LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, toRemove);
    

    【讨论】:

    • 谢谢,这真的很有帮助!抱歉回复晚了,我已经出国几天了!
    • 非常有帮助的答案。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-01
    • 2018-01-08
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多