我正在开发一个Android应用程序(minSDK = 8),这个应用程序有一张地图,上面有用户当前的位置。昨天,我正在修复路线制作的一些错误,一切都很好。然后,我不知道我做了什么,但设备的当前位置停止工作。我尝试调试,我注意到 OnLocationChanged 回调从未被调用。然后,我使用 Git 恢复到旧版本,我确信它正在工作,但它不起作用。所以我认为我的设备有问题。然后,为了确定检查,我打开了地图应用程序,它运行良好。所以...我不知道该怎么办。我仔细检查了设置-> 位置服务选项卡,所有 3 个选项(GPS、网络和 Google 位置)均已启用。
只是为了显示我的部分代码:
显现:
<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" />
地图活动:
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() 中设置了一个断点,但它从未被调用过。我不知道该怎么办。如果我可以访问另一台设备,我会尝试使用它。