简体   繁体   中英

android problem to get latitude & longitude from a given address

I am trying find lat & long from user given address, for that i am using following code,

GeoPoint pointForEnterAddr;


try {

    List<Address> address = coder.getFromLocationName(enterAddr, 1);

                    if (address == null)

                     pointForEnterAddr = null;

                    else {
                        Address location = address.get(0);
                        System.out.println("Lat in button click :"
                                + location.getLatitude());
                        System.out.println("Long in button click :"
                                + location.getLongitude());


pointForEnterAddr = new GeoPoint((int) (location.getLatitude() * 1E6),
                    (int) (location.getLongitude() * 1E6));


}
 catch (Exception ex) {
                    System.out.println("Error here :" + ex);
                }

But everytime it coming to catch part & shows exception, java.io.IOException: Service not Available

How can i solve it and get proper output? Plz tell me.

Thank you

I found this for your questions, I think it is the bug of emulator. Look at this answer

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

Just to mention an alternative, you can use the Google Maps' REST based reverse geocoder . You can probably use this as a fallback. As you would be using Google Maps in your app too, you should be good with the API rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM