私はこの投稿を使用しています : Android でユーザーの現在の場所を取得する最も簡単で堅牢な方法は何ですか? デバイスの現在の場所を取得します。そして私のコードは次のとおりです。
locationResult = new LocationResult() {
@Override
public void gotLocation(Location location) {
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
};
myLocation = new MyLocation();
myLocation.getLocation(this, locationResult);
mapController = mapView.getController();
point = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
mapController.animateTo(point);
Toast.makeText(getApplicationContext(), ("Latitude = "+latitude+" Longitude = "+longitude), Toast.LENGTH_SHORT).show();
mapController.setZoom(17);
mapView.invalidate();
緯度と経度は、グローバル double 型変数として宣言されます。しかし、アプリケーションを実行した後、ブルー スクリーンが表示されます。問題は、私のコードが緯度と経度の値を取得できないことだと思います。誰でも私を助けてもらえますか?ありがとう 。