Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Geofence on different Users

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);
    }
}
like image 509
umang gala Avatar asked Nov 15 '16 03:11

umang gala


People also ask

What are the disadvantages of geofencing?

Battery and Data Draining This can be a major drawback of geofencing for marketing purposes, as many users will disable location tracking and mobile data to prolong battery life. Such a practice can hinder your efforts to reach your target audience with personalized messages even if they opted-in to receiving them.

Can you do geofencing on your own?

Building your own geofences might seem like an easy task, but it's important to understand the many challenges involved. While it's possible for developers and product owners to set up geofencing in their apps, many companies come to the best geofencing software providers such as PlotProjects to complete the process.

What is the limit on the number of geofence for each app?

You can have multiple active geofences, with a limit of 100 per app, per device user. For each geofence, you can ask Location Services to send you entrance and exit events, or you can specify a duration within the geofence area to wait, or dwell, before triggering an event.

Can you geofence without an app?

An app – very important to note that geofences for 99,9% of the use cases cannot be used without an app. There are some minor exceptions, but most likely, if you are reading this blog post, you will need an application – whether your own or through a partner – that can be utilized for this purpose.


1 Answers

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?

like image 118
Flowra Avatar answered Sep 30 '22 13:09

Flowra