Creating Geofence for Different Users

We have access to the GoogleApiClient user since logging in to google account. The code below creates Geofence for the user who is currently registered. Example: user A is registered in the application, and we have access to GoogleApiClient , so the geofence is created using the addGeofences function, which takes the parameter as mGoogleApiClient (current GoogleApiClient user).

How can I create geofence for user B? How can I access his / her GoogleApiClient to create a geo object in User B? In short, how can we create geofence for 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); } } 
+6
source share
2 answers

I have the same question, and the ideas I'm thinking of are as follows:

  • you create a user. Create geofence for user B and save the center point and radius in a remote database, then user B will retrieve this data “either by push notification”, then add geofencing on device B depending on this data and implement when user B enters geofence , he will send a push notification to user A

or

  1. you will search for the location of user B every 5 minutes, and each time you retrieve the location, you will manually calculate the distance between the location of user B and the center point of the geofound, if it is less than the radius indicating user B inside the geofence.

I searched a lot in google geofence api, but I could not find anything useful in how to use api at another location point "not the current device location"


Notes:
the answer here shows you how to implement geofence manually: Is there any API for computing a Geofence violation other than the Android API .

I asked a question like yours, and maybe the answers will be useful:
Android: how to get a user to create geofences for other monitored users?

+1
source

Did you find a solution? I am also looking for code for your same problem, plz if you decide to share it. thank you

0
source

Source: https://habr.com/ru/post/1012326/


All Articles