我正在尝试在城市内制作圆形地理围栏,我希望此地理围栏的宽度为2公里,我想知道用户是否在此地理围栏内
我做了什么
private fun checkIfInsideGeoFence(){
geofenceList.add(Geofence.Builder()
// Set the request ID of the geofence. This is a string to identify this
// geofence.
.setRequestId("New York")
// Set the circular region of this geofence.
.setCircularRegion(
40.6882657,
-73.9398756,
2000F)
// Create the geofence.
.build())
geofencingClient.addGeofences(getGeofencingRequest(),geofencePendingIntent).addOnSuccessListener {
fusedLocationClient.lastLocation
.addOnSuccessListener { location : Location? ->
// Got last known location, here I need to check if its inside the geofence
}
}.addOnFailureListener{
}
}
private fun getGeofencingRequest(): GeofencingRequest {
return GeofencingRequest.Builder().apply {
setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
addGeofences(geofenceList)
}.build()
}
private val geofencePendingIntent: PendingIntent by lazy {
//Here I dont use a brodcast receiver since I dont need to know if the user enters or leaves the area, just if its inside
PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
我需要知道里面
fusedLocationClient.lastLocation
.addOnSuccessListener { location : Location? ->
// Got last known location, here I need to check if its inside the geofence
}
如何知道用户是否处于特定比例