Android problem to get latitude and longitude from given address

I try to find lat and long from the address specified by the user, for this I use the 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 every time he comes to catch a part and show an exception, java.io.IOException: service is unavailable

How can I solve this problem and get the right result? Plz tell me.

thank

+2
source share
2 answers

Just to mention an alternative, you can use Google Maps based REST reverse geocoder . You can probably use this as a reserve. Since you will also use Google Maps in your application, you should be good with the rules of the API.

0
+1

All Articles