我正在使用下面的代码监控地理围栏转换
LocationServices.GeofencingApi
.addGeofences(AssistApplication.getApiHelper().getClient(),
getGeofencingRequest(),
getPendingIntent(context,
GeofenceTransitionIntentService.class))
.setResultCallback(this);
这就是我构建 GeofencingRequest 的方式
private GeofencingRequest getGeofencingRequest()
{
return new GeofencingRequest.Builder()
.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER |
GeofencingRequest.INITIAL_TRIGGER_EXIT)
.addGeofence(getGeofence())
.build();
}
private Geofence getGeofence()
{
return new Geofence.Builder()
.setRequestId(requestId)
.setCircularRegion(latitude, longitude, 100)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
Geofence.GEOFENCE_TRANSITION_EXIT)
.build();
}
地理围栏在进入和退出时正确触发,但是当我使用 时getGeofenceTransition()
,我没有得到三个GEOFENCE_TRANSITION_
标志中的任何一个。
protected void onHandleIntent(Intent intent)
{
final GeofencingEvent event = GeofencingEvent.fromIntent(intent);
if (event.hasError())
{
Log.e(TAG, getErrorMessage(event.getErrorCode()));
return;
}
switch (event.getGeofenceTransition())
{
case Geofence.GEOFENCE_TRANSITION_EXIT:
// Not triggered
break;
case Geofence.GEOFENCE_TRANSITION_ENTER:
case Geofence.GEOFENCE_TRANSITION_DWELL:
// Not triggered
break;
default:
// Triggered on exit and enter
}
}
请告知我在这里缺少的东西