[英]Limit maximum GPS between 2 distances
我已经阅读了许多类似的文章,但我没有得到我需要的答案:
因此,我有一个应用程序连接到我的后端服务器,例如 onSite Attendance,其中用户(在这种情况下为技术人员)go 到某些地方并使用具有自动水印功能的照片功能在那里做文档(显示坐标和到站点的距离) ,
我设置了用户必须访问和拍照的坐标,但是我想限制到站点的距离,所以如果用户拍照超过100米的容忍度,应用程序会自动关闭,
目前我正在使用 Java 和 Kotlin 进行开发,
我怎样才能做到这一点?
这是获取位置的代码:
class LocationService(context: Context): LiveData<Result<Throwable, Location?>>() {
private var fusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
override fun onInactive() { // is called when the lifecycle owner(LocationActivity) is either paused, stopped or destroyed
super.onInactive()
fusedLocationClient.removeLocationUpdates(locationCallback)
}
override fun onActive() { // is called when the lifecycle owner(LocationActivity) is either started or resumed
super.onActive()
fusedLocationClient.lastLocation
.addOnSuccessListener { setLocationData(it) }
.addOnFailureListener {t -> setErrorData(t) }
startLocationUpdates()
}
private fun setLocationData(location: Location?) { // location is nullable as if GPS is turned off even if the last
// location was previously retrieve because disabling location clears the cache
//value = LocationEvent.OnLocationResult(Result.build { location })
value = Result.build { location }
}
private fun setErrorData(t: Throwable) {
//value = LocationEvent.OnLocationResult(Result.build { throw t })
value = Result.build { throw t }
}
private fun startLocationUpdates() {
Timber.d { "start location updates" }
fusedLocationClient.requestLocationUpdates(
locationRequest,
locationCallback,
null // looper
)
}
您可以使用Android 地理围栏
地理围栏将用户当前位置的感知与用户与可能感兴趣的位置的接近度的感知结合起来。 要标记感兴趣的位置,请指定其纬度和经度。 要调整该位置的接近度,请添加一个半径。 纬度、经度和半径定义地理围栏,在感兴趣的位置周围创建一个圆形区域或围栏。
您可以拥有多个活动的地理围栏,每个应用程序、每个设备用户的限制为 100 个。 对于每个地理围栏,您可以要求位置服务向您发送入口和出口事件,或者您可以指定地理围栏区域内的持续时间以在触发事件之前等待或停留。 您可以通过以毫秒为单位指定过期持续时间来限制任何地理围栏的持续时间。 地理围栏过期后,定位服务会自动将其删除。 更多的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.