首页 > 解决方案 > 设备位置在另一台设备上为空(GoogleMaps 活动)

问题描述

我目前正在开发我的第二个包含谷歌地图活动的安卓应用程序。在这个活动中,我想向用户展示他们当前的位置。我设法做到了,它适用于我的两种设备(华为 P smart 和 Galaxy S5)。我还向我的朋友发送了该应用程序的 APK,在他的设备(华为 P9 Lite)上,调用 task.getResult() 后,当前位置返回 null。在他的设备上,该方法将始终跳转到 else 语句(意味着 currentLocation == null)。我使用了以下方法。

private void getDeviceLocation() {
    Log.d(TAG, "getDeviceLocation: getting the devices current location");

    try {
        mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
            mFusedLocationProviderClient.getLastLocation()
            .addOnSuccessListener(this, new OnSuccessListener<Location>() {
                @Override
                public void onSuccess(Location currentLocation) {
                    Log.d(TAG, "onComplete: found location!");
                    if (currentLocation != null) {

                        moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),
                                DEFAULT_ZOOM);

                    } else {
                        Log.d(TAG, "onComplete: current location is null");
                        Toast.makeText(MapsActivity.this, "unable to get current location", Toast.LENGTH_SHORT).show();
                    }
                }
            });

    } catch (SecurityException e) {
        Log.e(TAG, "getDeviceLocation: SecurityException: " + e.getMessage());
    }
}

我已经尝试/做了以下事情:

因为我在自己的设备上没有任何问题,并且在我的 logcat 中找不到任何值得注意的东西(因为它都在我的设备上运行),所以我很难理解为什么会发生这种情况。

标签: javaandroidgoogle-maps

解决方案


推荐阅读