以下のコードを使用して、ジオフェンスの遷移を監視しています
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();
}
ジオフェンスは、開始時と終了時に正しくトリガーされますが、 を使用すると、3 つのフラグ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
}
}
ここで何が欠けているかアドバイスしてください