【问题标题】:Is 'constructor LocationRequest()' deprecated in google maps v2?谷歌地图 v2 中是否弃用了“构造函数 LocationRequest()”?
【发布时间】:2021-06-03 23:03:13
【问题描述】:

我最近偶然发现了这条消息,我很确定这个构造函数在 18.0.0 之前的版本中没有被弃用,但是我在任何地方都找不到这个被弃用的信息。

我们应该改用什么,有没有另一种方法来创建locationRequest

【问题讨论】:

    标签: android kotlin google-maps-android-api-2 google-location-services


    【解决方案1】:

    是的,LocationRequest 构造函数已弃用。您可以使用其静态方法LocationRequest.create() 来创建位置请求。

    科特林:

    locationRequest = LocationRequest.create().apply {
        interval = 100
        fastestInterval = 50
        priority = LocationRequest.PRIORITY_HIGH_ACCURACY
        maxWaitTime= 100
    }
    

    Java:

    locationRequest = LocationRequest.create()
        .setInterval(100)
        .setFastestInterval(3000) 
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
        .setMaxWaitTime(100);
    

    【讨论】:

    • 啊!!很好 !这是从哪个版本引入的?
    • 我认为在版本 18.0.0 构造函数被弃用之后。 LocationRequest.create() 总是在那里创建请求,但是在版本 18 之后,他们已将 setWaitForAccurateLocation(true) 添加到您的 LocationRequest。
    【解决方案2】:

    对于在 Flutter 的 geolocator 8.0.1 中遇到此错误的任何人。 现在尝试编辑FusedLocationClient.java:199。然后等待作者更新pub包

    来自

    LocationRequest locationRequest = new LocationRequest();
    

    LocationRequest locationRequest = LocationRequest.create();
    

    这是LocationRequest

    【讨论】:

      【解决方案3】:
       LocationRequest locationRequest = LocationRequest.create() //if you want access of variable
                                  .setInterval(100)
                                  .setFastestInterval(3000)
                                  .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                                  .setNumUpdates(1)
                                  .setMaxWaitTime(100);
      

      【讨论】:

      猜你喜欢
      • 2013-02-20
      • 2014-05-11
      • 2013-04-16
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      • 2014-08-18
      相关资源
      最近更新 更多