Creating Geofence on different Users
Asked Answered
D

1

6

We have access to user's GoogleApiClient since he/she signed in from google account. Below code creates Geofence on user currently signed in. Example, User A logs into application and we have access to GoogleApiClient, so geofence is created with addGeofences function which takes parameter as mGoogleApiClient(current user's GoogleApiClient).

How can I create geofence on User B? How can I have access to his/her GoogleApiClient to create geofence on User B? In short, how can we create geofence on other users? Please help!

public void addGeofencesButtonHandler(View view) {
    if (!mGoogleApiClient.isConnected()) {
        Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show();
        return;
    }

    try {
        populateGeofenceList();// creates geofence from list 
        LocationServices.GeofencingApi.addGeofences(
                mGoogleApiClient,
                // The GeofenceRequest object.
                getGeofencingRequest(),
                // A pending intent that that is reused when calling removeGeofences(). This
                // pending intent is used to generate an intent when a matched geofence
                // transition is observed.
                getGeofencePendingIntent()
        ).setResultCallback(this); // Result processed in onResult().
    } catch (SecurityException securityException) {
        // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
        logSecurityException(securityException);
    }
}
Donne answered 15/11, 2016 at 3:13 Comment(0)
E
1

I have the same question,and the ideas I am thinking of right now are:

  1. you make user A create geofence for user B and store the center point and radius in remote database, then user B will retrieve this data "or by push notification" and then add geofence on the device B depending on this data and implement when user B be enter the geofence, he will send push notification to user A

or

  1. you will retrieve user B location say every 5 min and every time you retrieved the location you will calculate manually the distance between the user B location and the center point of the geofence if it is less than radius that's mean user B is inside the geofence.

I searched a lot in google geofence api but I couldn't find anything helpful of how to use the api on another location point "not current device location"


Notes:
the answer here show you how to implement geofence manually : Is there any API for calculating Geofence breach other than Android API's

I asked a question like yours here and may be the answers will be helpful:
Android: How to make user create geofence for another tracked users?

Ebberta answered 16/11, 2016 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.