views:

290

answers:

3

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

A: 

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.

BrennaSoft
urobo
+2  A: 

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

urobo
thanks mate, that solved my problem too!
bodom_lx
A: 

I'm getting an empty list back doing a reverse geocode (getFromLocation) on a Droid X, which I'm guessing has nothing to do with an AVD. Maybe I'm targeting the wrong ARD (Android Real Device)? ;-) Any ideas?

Cryptognome
Ok, I think I've figured it out. Half the time, this call just returns an empty list. Either the geocoder doesn't try very hard (connectivity is a factor, obviously) or maybe the service itself gets overloaded. Requesting too often may increase your rejection chances (say less than 30 secs apart), but in any case, be prepared to deal with a lot of goose eggs.
Cryptognome