gpt4 book ai didi

android - 即使我们在 android 中移动数英里之外,位置管理器也无法正确检测到位置

转载 作者:行者123 更新时间:2023-11-30 04:50:09 27 4
gpt4 key购买 nike

在我的应用程序中,我必须获取当前位置。首先它正确获取位置。但是我们正在从当前位置移动到其他位置。它显示以前的地址。它没有更新位置。我的代码是:

locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
locListener = new MyLocationListener();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locListener);
location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location != null)
{
latitude = location.getLatitude();
longitude = location.getLongitude();
}


//My location listener is as follows

public void onLocationChanged(Location loc) {
if (loc != null) {
//Toast.makeText(this.getBaseContext(),
//"Location changed : Lat: " + loc.getLatitude() +
//" Lng: " + loc.getLongitude(),
//Toast.LENGTH_LONG).show();
double lat = loc.getLatitude();
double lon = loc.getLongitude();
}
}

public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}

public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}

public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}

请找出错误,当我第一次启动时它没有工作,第二次它本身正在工作....所以也检查一下这个东西......

最佳答案

尝试:

locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,2000,2,locListener);

这告诉它如果自上次移动至少 2 米后尝试每 2 秒报告一次。 0 可能会被区别对待。

也许您手机的 GPS 有问题(有些手机因此而臭名昭著)。 Google map 有什么问题吗?

在您的代码中,您还可以调用 [myLocationManager.getBestProvider(new Criteria(), false)][1]

如果出现问题,这将返回 GPS 以外的内容。可能是网络提供的位置更准确。

[1]: http://developer.android.com/reference/android/location/LocationManager.html#getBestProvider(android.location.Criteria , bool 值)

关于android - 即使我们在 android 中移动数英里之外,位置管理器也无法正确检测到位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3733311/

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