I'm implementing a simple Geo-coding example where user enters an address and gets its latitude and longitude.
addr = Area_edtxt.getText().toString();
try {
list_addr = gc.getFromLocationName(addr, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("Location lookup failed", e.getMessage());
}
if (list_addr != null && list_addr.size() > 0 ){
latitude = list_addr.get(0).getLatitude();
longitude = list_addr.get(0).getLongitude();
开发者_如何学Python latitude_edtxt.setText(latitude.toString());
longitude_edtxt.setText(longitude.toString());
}else {
latitude_edtxt.setText("Address not found");
}
but shows me error : Unable to open stack trace file '/data/anr/traces.txt' : Permission denied.
For a quick try you could use an AsyncTask http://developer.android.com/reference/android/os/AsyncTask.html
private class GeocodeTask extends AsyncTask<String, Integer, List> {
protected Long doInBackground(String... address) {
try {
return gc.getFromLocationName(address[0], 1)
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("Location lookup failed", e.getMessage());
}
}
protected void onPostExecute(List result) {
if (list_addr != null && list_addr.size() > 0 ){
latitude = list_addr.get(0).getLatitude();
longitude = list_addr.get(0).getLongitude();
latitude_edtxt.setText(latitude.toString());
longitude_edtxt.setText(longitude.toString());
}else {
latitude_edtxt.setText("Address not found");
}
}
}
new GeocodeTask().execute(addr);
精彩评论