Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

geocoding - Android; Geocoder, why do I get "the service is not available"?

I want to use the Geocoder in an android application, I've got the following piece of code to sample it :

public class LocatorGeo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        Geocoder geo = new Geocoder(getApplicationContext());

        List<Address> myAddrs = new ArrayList<Address>();

        try {
            myAddrs = geo.getFromLocationName("CO100AR", 1);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

I get the following stack trace :

09-01 15:52:38.809: WARN/System.err(334): java.io.IOException: Service not Available
09-01 15:52:38.819: WARN/System.err(334):     at android.location.Geocoder.getFromLocationName(Geocoder.java:159)
09-01 15:52:38.829: WARN/System.err(334):     at com.jameselsey.LocatorGeo.onCreate(LocatorGeo.java:25)
09-01 15:52:38.829: WARN/System.err(334):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-01 15:52:38.839: WARN/System.err(334):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-01 15:52:38.849: WARN/System.err(334):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-01 15:52:38.849: WARN/System.err(334):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-01 15:52:38.868: WARN/System.err(334):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-01 15:52:38.868: WARN/System.err(334):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-01 15:52:38.879: WARN/System.err(334):     at android.os.Looper.loop(Looper.java:123)
09-01 15:52:38.889: WARN/System.err(334):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-01 15:52:38.899: WARN/System.err(334):     at java.lang.reflect.Method.invokeNative(Native Method)
09-01 15:52:38.909: WARN/System.err(334):     at java.lang.reflect.Method.invoke(Method.java:521)
09-01 15:52:38.919: WARN/System.err(334):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-01 15:52:38.929: WARN/System.err(334):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-01 15:52:38.929: WARN/System.err(334):     at dalvik.system.NativeStart.main(Native Method)

Why is the service unavailable? I have the following in my manifest

   <uses-permission android:name="android.permission.INTERNET"/>

The documentation states : The Geocoder class requires a backend service that is not included in the core android framework, how/where can I obtain such a service?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's a bug in the emulator for 2.2 http://code.google.com/p/android/issues/detail?id=8816


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...