0
我試圖使用反向地理編碼與AsyncTask,但我不知道如何傳遞doInBackground()方法中的參數與緯度縱座標,然後執行AsyncTask。如何獲取doInBackground方法內的經緯度參數?
public static class NameAsyncTask extends AsyncTask<String, Void, String> {
Context mContext;
public GetAddressTask(Context context) {
super();
mContext = context;
}
@Override
protected String doInBackground(String... arg0) {
Geocoder gc = new Geocoder(mContext, Locale.getDefault());
List<Address> list = null;
String city = "";
try {
list = gc.getFromLocation(lat, lng, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (list != null && list.size() > 0) {
Address address = list.get(0);
city = String.format("%s, %s", address.getAdminArea(), address.getCountryName());
}
return city;
}
@Override
protected void onPostExecute(String city) {
tituloTxt.setText(city);
}
}