Reputation: 786
I'm using the android.location.Geocoder for the first time. The Idea is: I have a Listener on a button which takes input from an EditText and resolve the location. Up to now it's debugging phase, so I have no handler taking messages from the thread, only geocoding and write to logcat. Q: Why this method always returns an empty list of Address objects?
private View.OnClickListener checkLocation = new View.OnClickListener() {
@Override
public void onClick(View v) {
location = ((EditText)findViewById(R.id.getLocation)).getText().toString();
Thread thr = new Thread(){
public void run (){
Log.d("Looking for", location);
Geocoder gc = new Geocoder(ctx,Locale.ITALY);
try {
fa= gc.getFromLocationName(location, 3);
if (fa.isEmpty())Log.d("getFromLocationName", "NothingFound");
else
{
int size= fa.size();
for (int i = 0; i<size ;i++)
Log.d("getFromLocationName.at("+ String.valueOf(i) +")", fa.get(i).getAddressLine(0)+", "+fa.get(0).getAddressLine(1));
}
} catch (IOException e) {
Log.e("IOException", e.getMessage());
}
}
};
thr.start();
}
};
manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Somebody knows why? (btw I am using 1.6 sdk) Input tried
Upvotes: 1
Views: 5748
Reputation: 786
the project wasn't targeting the correct AVD. To use geolocation you have to make it point an avd implementing the google APIs. Once I changed it everything worked just fine. Sorry for bothering
Upvotes: 4
Reputation: 73484
Because it doesn't recognize the address you are putting in or it can't reach the service.
What address are you putting in? Try something as simple as a zip code or city or state name.
Upvotes: 0