why Geocoder.getFromLocationName(…) returns an empty list?

别来无恙 提交于 2019-12-10 22:27:04

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/2865154/why-geocoder-getfromlocationname-returns-an-empty-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!