だから私は現在の位置を取得するためのアプリケーションを作成しています。以下のコードは正常に機能しています
文字列stringAddress="";
public void getLocation(View view){
最終的なLocationManagerlm=(LocationManager)getSystemService(LOCATION_SERVICE);
基準kriteria=new Criteria();
kriteria.setAccuracy(Criteria.ACCURACY_FINE);
kriteria.setAltitudeRequired(false);
kriteria.setBearingRequired(false);
kriteria.setCostAllowed(true);
kriteria.setPowerRequirement(Criteria.POWER_LOW);
最終的な文字列プロバイダー=lm.getBestProvider(kriteria、true);
最終的な場所lokasi=lm.getLastKnownLocation(provider);
updateWithNewLocation(lokasi);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER、2000、5、ll);
edittext_position.setText(stringAddress);
}
private void updateWithNewLocation(Location
if(lokasi!= null){
double lat = lokasi.getLatitude();
double lng = lokasi.getLongitude();
Geocoder gc = new Geocoder(this、Locale.getDefault());
試す{
リストアドレス=gc.getFromLocation(lat、lng、1);
StringBuilder sb = new StringBuilder();
if(addresses.size()> 0){
アドレスアドレス=addresses.get(0);
sb.append(address.getAddressLine(0));
stringAddress = sb.toString();
}
} catch(例外e){
}
}
}
private final LocationListener ll = new LocationListener(){
public void onStatusChanged(String Provider、int status、Bundle extras){
}
public void onProviderEnabled(文字列プロバイダー){
}
public void onProviderDisabled(文字列プロバイダー){
updateWithNewLocation(null);
}
public void onLocationChanged(Location location){
updateWithNewLocation(location);
}
}
しかし、問題は、getLocation()関数を呼び出すたびに、結果を返す前にアプリケーションが数秒間ハングすることです。aSyncTaskを使用してこの問題を解決することは知っていますが、開始方法がわかりません。あなたの助けに感謝。
ありがとうございました