Я пытаюсь создать круговую геозону внутри города, хочу, чтобы эта геозона была круговой шириной 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
}
Как узнать, находится ли пользователь в этом заданном c соотношении