gpt4 book ai didi

android - 没有得到位置更新

转载 作者:行者123 更新时间:2023-11-30 04:07:29 25 4
gpt4 key购买 nike

在我的 map 应用程序中,我似乎没有获得位置更新,我上了车并开始四处行驶,但我的位置标记在 map 上从未改变,甚至给了我一个 null lat and 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);

我的 onLocationChanged 监听器

@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 中,我注册再次收听,因为我可以从 map 开始新的 Activity

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

我做错了什么?

最佳答案

我想通了,这是因为我的提供者不匹配

关于android - 没有得到位置更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11379904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com