私は Android アプリ (minSDK=8) を開発しています。このアプリには、ユーザーの現在の場所が描かれた地図があります。昨日、ルートメイキングでいくつかのバグを修正していましたが、すべて問題ありませんでした。その後、何をしたかわかりませんが、デバイスの現在の場所が機能しなくなりました。デバッグしようとしましたが、OnLocationChanged コールバックが呼び出されないことに気付きました。その後、Git を使用して古いバージョンに戻しましたが、動作していることは確かですが、動作しません。したがって、私のデバイスに問題があると思います。次に、確認するために Maps アプリを開きましたが、問題なく動作しました。だから…どうしたらいいのかわからない。[設定] -> [位置情報サービス] タブを再確認しましたが、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() に入れても、決して呼び出されないということです。どうすればいいのかわからない。別のデバイスにアクセスできる場合は、それを試してみます。