Android:如何让用户为其他跟踪用户创建地理围栏? [英] Android: How to make user create geofence for another tracked users?

查看:49
本文介绍了Android:如何让用户为其他跟踪用户创建地理围栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实施Geofence来跟踪其他用户?
我正在开发一个将跟踪家庭成员的应用程序,并且我想实现Geofence功能,该功能将使用户能够执行以下操作:
用户A将跟踪用户B
用户A将确定地理围栏区域,用户B将在何时进入此地理围栏,用户A将收到通知

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

我每10分钟获取一次用户B的位置,我想为用户B创建地理围栏,当用户B进入地理围栏区域时,它将通知用户A

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

我尝试像这样使用Google Geofence:

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());

但是它仅适用于用户设备用户A位置",不适用于其他用户位置.

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

推荐答案

我想您应该添加一个数据库并跟踪谁在谁身上创建了地理围栏.还要在数据库中存储地理围栏半径和中心点.为了检查用户是否在地理围栏内,请从用户位置坐标和所有地理围栏坐标计算距离,然后在5分钟的跨度内将距离与半径进行比较.如果距离<半径,用户位于其他内部.如果用户在内部,则设置该标志以避免重复通知.如果用户外出重置标志.我认为应该可以.

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.

这篇关于Android:如何让用户为其他跟踪用户创建地理围栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆