Android 如何从公共列表中检索触发的地理围栏的纬度和经度<;土工围栏>;getTriggeringGeofences()

Android 如何从公共列表中检索触发的地理围栏的纬度和经度<;土工围栏>;getTriggeringGeofences(),android,geofencing,Android,Geofencing,我是Android新手,我正在从事一个地理围栏项目 是否可以从公共列表getTriggeringGeofences()检索触发的地理围栏的纬度和经度 我希望在收到通知警报和用户单击通知后,在地图中显示触发的位置。单击通知时,将显示带有所有已触发地理围栏的mapActivity。 要添加标记,我需要触发位置的LatLong。如何实现此目的?您可以从IntentService geofence事件获取纬度和经度 GeofencingEvent GeofencingEvent=GeofencingEv

我是Android新手,我正在从事一个地理围栏项目

是否可以从公共列表getTriggeringGeofences()检索触发的地理围栏的纬度和经度

我希望在收到通知警报和用户单击通知后,在地图中显示触发的位置。单击通知时,将显示带有所有已触发地理围栏的mapActivity。
要添加标记,我需要触发位置的LatLong。如何实现此目的?

您可以从IntentService geofence事件获取纬度和经度

GeofencingEvent GeofencingEvent=GeofencingEvent.fromIntent(intent)

在intent服务上,geofence被触发,因此您将在此处添加PIN:

public class GeofenceTransitionsIntentService extends IntentService {

protected void onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        String errorMessage = GeofenceErrorMessages.getErrorString(this,
                geofencingEvent.getErrorCode());
        Log.e(TAG, errorMessage);
        return;
    }

    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();

    // Test that the reported transition was of interest.
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
            geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {

        // Get the geofences that were triggered. A single event can trigger
        // multiple geofences.
        List triggeringGeofences = geofencingEvent.getTriggeringGeofences();

        // Get the transition details as a String.
        String geofenceTransitionDetails = getGeofenceTransitionDetails(
                this,
                geofenceTransition,
                triggeringGeofences
        );

        // Send notification and log the transition details.
        sendNotification(geofenceTransitionDetails);
        Log.i(TAG, geofenceTransitionDetails);
    } else {
        // Log the error.
        Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
                geofenceTransition));
    }
}
Android官方文档提供了一个很好的关于实施地理围栏的教程:


您可以从GeofencingEvent获得它

protected void onHandleIntent(Intent intent) {
    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
    if (geofencingEvent.hasError()) {
        //TODO: Error handling

        return;
    }

    Location location = geofencingEvent.getTriggeringLocation();
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();
}

是的,我用了同样的方法。我想知道我们是否可以从每个地理围栏中单独提取纬度和逻辑度。例如:geopfence.getRequestId()只返回请求id。类似的方法,我们可以从下面记录的geofence中提取latlong:geofence[圆圈id:卫星城镇过渡:110.006100,76.331200 1000m,resp=0s,dwell=-1ms,@187017824]我需要过渡:110.006100,76.331200单独一部分。