Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法获取位置更新_Android_Android Location - Fatal编程技术网

Android 无法获取位置更新

Android 无法获取位置更新,android,android-location,Android,Android Location,在我的地图应用程序中,我似乎没有得到位置更新,我上了车,开始四处开车,但我的位置标记在地图上从未改变,甚至给了我一个null lat和long locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); Str

在我的地图应用程序中,我似乎没有得到位置更新,我上了车,开始四处开车,但我的位置标记在地图上从未改变,甚至给了我一个
null lat和long

locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);

    String provider = locationManager.getBestProvider(criteria, true);
    if(provider == null){
        provider = LocationManager.NETWORK_PROVIDER;
    }
locationManager.requestLocationUpdates(provider, 60000, 5, this);
我的位置改变了

@Override
public void onLocationChanged(Location location) {
    Logging logger = new Logging();
    logger.append("V", className, "onLocationChanged(Fine)", "Accuracy: " + location.getAccuracy());

    try {
        userLat = Double.toString(location.getLatitude());
        userLong = Double.toString(location.getLongitude());

        int mLat = (int) (location.getLatitude() * 1000000);
        int mLng = (int) (location.getLongitude() * 1000000);

        userLocation = new GeoPoint(mLat, mLng);

        if (!initialFix && mapSettingShowLoc) {
            showUserLocation(userLocation);
            initialFix = true;
        }

        if (mapSettingShowLoc) {
            showUserLocation(userLocation);
        }

    } catch (Exception e) {
        logger.append("E", className, "onLocationChanged", "Exception: " + e);
    }
}
在我的
onResume
中,我注册再次收听,因为我可以从地图开始新的活动

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, this);

我做错了什么?

我想出来了,是因为我找不到匹配的提供商

我想出来了,是因为我找不到匹配的提供商

所以你有位置更新吗?另外,我注意到,在第一个区块中,你要求每隔60秒在2米处进行“粗略”更新(网络),在onresume中,你要求在2秒1米处进行GPS更新。根据经验,我会特别询问您想要什么GPS、网络,或者两者都需要,而不是让系统决定(许多实现在应该使用GPS时使用网络,反之亦然,这取决于设备)。当您同时启动Google Maps时会发生什么?这样行吗?是的,谷歌地图很好用,我几乎每天都用它。我唯一一次更改位置是在活动的第一次运行时。如果我在我的
onPause
中导航到一个名为
removeUpdates
的新活动,那么当你看到我的简历时,我不会再接到另一个名为
onLocationChange
的电话,那么你是否得到了位置更新?另外,我注意到,在第一个区块中,你要求每隔60秒在2米处进行“粗略”更新(网络),在onresume中,你要求在2秒1米处进行GPS更新。根据经验,我会特别询问您想要什么GPS、网络,或者两者都需要,而不是让系统决定(许多实现在应该使用GPS时使用网络,反之亦然,这取决于设备)。当您同时启动Google Maps时会发生什么?这样行吗?是的,谷歌地图很好用,我几乎每天都用它。我唯一一次更改位置是在活动的第一次运行时。如果我在我的
onPause
中导航到一个名为
removeUpdates
的新活动,那么正如您看到的我的简历,在那之后我不会再接到另一个名为
onLocationChange
的电话