我嘗試使用AsyncTask反向地理編碼,但通過doInBackground()方法的緯度和經度參數未正確發生。任何想法?如何在doInBackground方法中傳遞參數緯度和經度?
public class SitesAdapter extends ArrayAdapter<StackSite> {
public static Double lat;
public static Double lng;
@Override
public View getView(int pos, View convertView, ViewGroup parent){
...
lat = -1.80;
lng = -80.20;
...
}
public void start(){
new GetAddressTask(mContext).execute(lat, lng);
}
public static class GetAddressTask extends AsyncTask<Double, Void, String> {
//mContext
@Override
protected String doInBackground(Double... params) {
Geocoder gc = new Geocoder(mContext, Locale.getDefault());
List<Address> list = null;
String city = "";
double latitude = params[0];
double longitude = params[1];
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);
}
}
}
錯誤:
11-21 15:10:24.409: E/Trace(24502): error opening trace file: No such file or directory (2)
基本的Java。你是否熟悉領域,制定者和獲得者? – Preetygeek 2014-11-21 18:02:07
RTFM。它就在那裏: http://developer.android.com/reference/android/os/AsyncTask.html – IuriiO 2014-11-21 18:17:43
您提供的錯誤是無用的。堆棧跟蹤在哪裏?一些有用的信息?你不知道你在做什麼。 – Preetygeek 2014-11-21 20:52:52