Geofence in Android not working based on current location of user

119 views Asked by At

Want to achive -> as user move forward/enter to location all the nearest 200 meter geofence should trigger.

Note -> we will be having multiple location lat/long based on their name

Use Case -> In case user add burger king -> all the burger king location will be added in server & user get location enter notification only nearest 200 meter burger king on only & only enter of that store.

Whats going on currently -> In my application i want to add multiple geofences on different location according to the user and as user move forwards towards the area the geofences will sort based on their location and first 100 geofence will be triggered. But what is happening (or am i thinking) that on updating the location throught location request like below

mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());

Upon updating the location i am removing all geofence & adding new geofence with sorting based on nearest location again

mLocationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(LocationResult locationResult) { -- }

this leads triggering multiple geofence if i chose my GeofencingRequest builder like below->

builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);

what i found solution to this problem is to set my GeofencingRequest like below

builder.setInitialTrigger(0);

& add a delay in request location update of 10 second

so this will not trigger if user is already in geofence but will only trigger with enter of geofence.

Problem -> main problem is that sometime location reminders works correctly but another time it's not. & Sometimes its working correctly on my phone(one plus nord 2) but not on my friends phone (samsung S23)

0

There are 0 answers