J'utilise le android.location.Geocoder pour la première fois. L'idée est la suivante: J'ai un écouteur sur un bouton qui prend l'entrée d'un EditText et résout l'emplacement. Jusqu'à présent, c'est la phase de débogage, donc je n'ai aucun gestionnaire qui prend des messages du thread, seulement le géocodage et l'écriture dans logcat. Q: Pourquoi cette méthode renvoie-t-elle toujours une liste vide d'objets Address?pourquoi Geocoder.getFromLocationName (...) retourne une liste vide?
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();
}
};
manifeste:
<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" />
Quelqu'un sait pourquoi? (BTW j'utilise 1,6 sdk) Entrée essayé
merci compagnon, qui a résolu mon problème aussi! – dgraziotin