Android FusedLocationProviderClient并非总能正常工作

时间:2018-12-25 14:35:26

标签: android fusedlocationproviderclient

我用三部手机测试了此代码。它适用于其中两个,但不适用于第三个 Huawei y9 2019 。有什么问题? ,为什么显示(?)和(*)符号?

我的代码是:

# Complete the solve function below.
def solve(s):
    return (" ".join([x.lower().capitalize() for x in s.split(' ')]))

enter image description here

1 个答案:

答案 0 :(得分:0)

我已经检查过华为以前的版本以及其他手机,它对我来说很好用。但是我还没有华为y92019。所以您可以使用以下代码进行检查。

//通过FusedLocationApi请求位置

public void registerRequestUpdate(final LocationListener listener) {
        mLocationRequest = LocationRequest.create();
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        localStorageInterval=sm.getLocalStorageInterval().get("localStorageInterval")*1000;
        mLocationRequest.setInterval(NOTIFY_INTERVAL/2); // every second


        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                try {
                    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, listener);
                } catch (SecurityException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                    if (!isGoogleApiClientConnected()) {
                        mGoogleApiClient.connect();
                    }

                    registerRequestUpdate(listener);
                 //   saveLocationAndSync();

                }
            }
        }, NOTIFY_INTERVAL);
    }

//通过此方法获取更新的位置

 @Override
    public void onLocationChanged(Location location) {
        try {
              string lat = location.getLatitude(); 
              string long = location.getLongitude();

            }
        }catch (Exception ex){
            //exception
        }
    }