Android: How to make user create geofence for another tracked users?
Asked Answered
R

1

1

How to implement Geofence for tracking another users?
I am developing an application which will track family members, and I want to implement Geofence feature which will enable user to do for ex:
user A will track user B
user A will determine the geofence area and when user B will enter this geofence user A will get a notification

I retreived the location of user B every 10 minutes and I want to create Geofence for user B which will notify user A when user B enter the geofence area

I try to use google Geofence like this code :

mGeofenceList.add(new Geofence.Builder()
// Set the request ID of the geofence. This is a string to identify this
// geofence.
.setRequestId(entry.getKey())

.setCircularRegion(
        entry.getValue().latitude,
        entry.getValue().longitude,
        Constants.GEOFENCE_RADIUS_IN_METERS
)
.setExpirationDuration(Constants.GEOFENCE_EXPIRATION_IN_MILLISECONDS)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
        Geofence.GEOFENCE_TRANSITION_EXIT)
.build());

but it just work for the user device "user A location" not for another user location.

Rounds answered 14/11, 2016 at 23:13 Comment(1)
did you find any solution? And is it really possible to acheive that?Impressionism
C
2

I guess you should add a database and keep track of who created geofence on whom. Also store geofence radius and center point in the database. In order to check if user is inside geofence, calculate distance from user location coordinates and all geofences coordinates and then compare the distance with radius in 5 minutes span. If distance < radius, user is inside else outside. If user is inside set the flag to avoid repeated notifications. If user goes outside reset the flag. I think this should work.

Christmastide answered 16/11, 2016 at 2:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.