开发者

android problem to get latitude & longitude from a given address

开发者 https://www.devze.com 2023-03-15 03:22 出处:网络
I am trying find lat & long from user given address, for that i am using following code, GeoPoint pointForEnterAddr;

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);

                    开发者_Go百科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.

0

精彩评论

暂无评论...
验证码 换一张
取 消