gpt4 book ai didi

Android LocationListener 停止工作

转载 作者:行者123 更新时间:2023-11-30 03:37:12 25 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序 (minSDK=8),这个应用程序有一张 map ,上面绘制了用户的当前位置。昨天,我正在修复一些路线制定的错误,一切都很好。然后,我不知道我做了什么,但设备的当前位置停止工作了。我尝试调试,发现从未调用过 OnLocationChanged 回调。然后,我使用 Git 恢复到旧版本,我确信它可以工作,但它不工作。所以我认为我的设备有问题。然后,为了确定它,我打开了 map 应用程序,它运行良好。所以……我不知道该怎么办。我仔细检查了“设置”->“位置服务”选项卡,所有 3 个选项(GPS、网络和 Google 位置)均已启用。

只是展示我的部分代码:

list :

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

map Activity :

locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
if (currentPosition == null){
currentPosition = new LatLng(location.getLatitude(), location.getLongitude());
gas_list = new ArrayList<Gasolineres>();
gas_marker_list = new ArrayList<Marker>();
Thread thread = new Thread(null, obteEstacions, "MagentoBackground");
thread.start();

} else {
currentPosition = new LatLng(location.getLatitude(), location.getLongitude());
}
if (currentPosition != null){
if (myPosition == null){
myPosition = mapView.addMarker(new MarkerOptions().position(currentPosition).snippet("Lat: " + currentPosition.latitude + "\nLon: " + currentPosition.longitude).icon(BitmapDescriptorFactory.fromResource(R.drawable.current)));
} else {
myPosition.setPosition(currentPosition);
}
}

}
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10, locationListener);

问题是,我在 onLocationChanged() 中放置了一个断点,但它从未被调用过。我不知道该怎么办。如果我可以访问另一台设备,我会尝试使用它。

最佳答案

看来你的 gps 工作不正常......尝试将 Log 放入你的应用程序,这样你就可以在调用该方法时查看 DDMS logcat,在方法中试试这个:

Log.d(TAG, "OnLocationChanged was called");

也可以尝试安装 GPS Status 等应用,看看您的 GPS 是否正常工作

关于Android LocationListener 停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16485814/

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