我尝试使用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