【问题标题】:Connecting GoogleApiClient before using FucedLocationProviderClient在使用 FusedLocationProviderClient 之前连接 Google Api 客户端
【发布时间】:2020-07-21 10:53:01
【问题描述】:

在使用 FucedLocationProviderClient 之前,我需要先连接 GoogleApiClient 吗?

【问题讨论】:

    标签: android google-api location


    【解决方案1】:

    不。您不需要 GoogleApiClient。 FusedLocationProviderClient 将在没有 GoogleApiClient 的情况下工作。

    使用 FusedLocationProviderClient 获取位置的示例代码。

    private FusedLocationProviderClient mFusedLocationClient;
    
    //Intialize
    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    
    //After get it the permission and GPS ON - write this below code
    fusedLocationClient.getLastLocation()
        .addOnSuccessListener(this, new OnSuccessListener<Location>() {
            @Override
            public void onSuccess(Location location) {
                // Got last known location. In some rare situations this can be null.
                if (location != null) {
                    //handle location
                }
            }
        });
    

    参考这个 - https://medium.com/@droidbyme/get-current-location-using-fusedlocationproviderclient-in-android-cb7ebf5ab88e

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-18
      相关资源
      最近更新 更多