在不同用户上创建地理围栏

uma*_*ala 6 java mysql android server-side android-studio

我们可以访问用户,GoogleApiClient因为他/她从谷歌帐户登录.下面的代码在当前登录的用户上创建了Geofence.例如,用户A登录到应用程序并且我们可以访问GoogleApiClient,因此使用addGeofences函数创建地理围栏,该参数将参数作为mGoogleApiClient(当前用户的GoogleApiClient).

如何在用户B上创建地理围栏?如何访问他/她的GoogleApiClient以在用户B上创建地理围栏?简而言之,我们如何为其他用户创建地理围栏?请帮忙!

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

Flo*_*wra 1

我也有同样的问题,我现在想到的想法是:

  1. 您让用户 A 为用户 B 创建地理围栏并将中心点和半径存储在远程数据库中,然后用户 B 将“或通过推送通知”检索此数据,然后根据此数据在设备 B 上添加地理围栏并在用户 B 时实施进入地理围栏后,他会向用户 A 发送推送通知

或者

  1. 您将每隔 5 分钟检索一次用户 B 的位置,每次检索位置时,您将手动计算用户 B 位置与地理围栏中心点之间的距离,如果该距离小于半径,则表示用户 B 在地理围栏内。

我在 google geofence api 中搜索了很多,但找不到任何关于如何在另一个位置点“不是当前设备位置”上使用 api 的有用信息


注意:
这里的答案向您展示如何手动实现地理围栏: 除了Android API之外,还有其他API可以计算地理围栏违规吗

我在这里问了一个像你这样的问题,答案可能会有帮助:
Android: How to make user create geofence for another tracked users?