【问题标题】:Get android.gms.location.Geofence gps location details/coordinates - point of crossing the fence?获取 android.gms.location.Geofence gps 位置详细信息/坐标 - 穿越围栏的点?
【发布时间】:2021-09-17 09:37:26
【问题描述】:

是否可以获得Geofence gps 位置详细信息 - 即越过围栏的点?

  1. 我在位置 x,y, 半径处设置了地理围栏
  2. 我穿过栅栏,我的位置是 x2, y2

如何在不再次调用 GPS 请求的情况下轻松获取 x2、y2?

class GeofenceLocationReceiver: BroadcastReceiver() {
  [...]

  override fun onReceive(context: Context?, intent: Intent?) {
    val geofencingEvent = GeofencingEvent.fromIntent(intent)
    if (geofencingEvent.hasError()) {
      val errorMessage = GeofenceStatusCodes.getStatusCodeString(geofencingEvent.errorCode)
      Log.e(Category.LOCATION, "GEOFENCE result has errors: $errorMessage")
      return
    }
    if (geofencingEvent.geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geofencingEvent.geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {

      geofencingEvent.triggeringGeofences.firstOrNull()?.let {
        val geofenceId = it.requestId
        // HERE - HOW TO GET X2, Y2 - GPS coordinates?
      }
    } else {
       Log.e(Category.LOCATION, "INVALID TYPE")
    }
  }
}

【问题讨论】:

    标签: geofencing android-gps android-geofence


    【解决方案1】:

    geofencingEvent.getTriggeringLocation() 返回一个Location 其中有getLatitude()getLongitude()

    位置 (x2,y2) 对于每个触发的地理围栏都是相同的,因此没有理由在您的迭代器中调用它。

    Location location = geofencingEvent.getLocation();
    double x2 = location.getLongitude();
    double y2 = location.getLatitude();
     
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      • 2012-12-11
      • 2023-03-16
      • 1970-01-01
      • 2011-07-03
      相关资源
      最近更新 更多