i am trying to run a sample of fencing in android. i am showing a fence with a radius of 2 meter on a google map and at the same time i am showing my current location with 2 meter radius.
as you can see in a below image that my current location ( in green ) is far from the fence ( in red ) but still neither my Geofence.GEOFENCE_TRANSITION_EXIT
nor IntentService
is not getting called.
even when i get entered into the fence nothing gets notified.
i have seen other threads but nothing is getting worked.
here are my basic settings
<service
android:name=".GeofenceTransitionsIntentService"
android:exported="false"
>
</service>
pending intent
private PendingIntent getGeofenceTransitionPendingIntent() {
Intent intent = new Intent(this, GeofenceTransitionsIntentService.class);
return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
inside onConnected
mGeofenceRequestIntent = getGeofenceTransitionPendingIntent();
LocationServices.GeofencingApi.addGeofences(mApiClient, mGeofenceList,
mGeofenceRequestIntent);
i tried it with a BroadcastReceiver but no luck
private PendingIntent getmGeofenceTransitionPendingIntentReceiver(){
if(mGeofenceRequestIntent!=null){
return mGeofenceRequestIntent;
}else{
Intent intent = new Intent(GEOFENCE_RECEIVER);
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
}
inside my manifest file
<receiver android:name=".GeofenceReceiver" android:exported="false">
<intent-filter>
<action android:name="com.geofence.georeceiver"/>
</intent-filter>
</receiver>
Your current radius should be less than the radius of the geofence. The ENTERED event only triggers once your entire "radius circle" is inside that of the geofence.
Also 2m for a geofence is very small, and I would suggest at the very least ±10m.