android - Geocoder.getFromLocationName() is not working in ICS device
Asked Answered
P

2

11

I have two devices. One is HTC WildFire S and other one is HTC 1V. I used the Geocoder.getFromLocationName() in my application. It is running successfully in the HTC wildfire S. But in the HTC 1V i got the following error. why it's came? How can i solve this? please can anybody help me.

Code

Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); 
//s is the address
List<Address> addresses = geoCoder.getFromLocationName(s, 5); //Here i got the following Exception.

Error

06-18 16:28:17.933: W/System.err(4960): java.io.IOException: Service not Available
06-18 16:28:17.953: W/System.err(4960):at android.location.Geocoder.getFromLocationName(Geocoder.java:178)

Location Tab

enter image description here

Pongee answered 19/6, 2012 at 10:20 Comment(5)
That's just a warning that the geocoder is not available, have you got Internet access setup on the One V? The Geocoder needs Internet access to retrieve the result. EDIT: Your app isn't crashing at this stage is it?Dissent
Yes, i have the internet permission.Pongee
Yes but does the device have connectivity? Can you browse the web on the device at the time of your testing?Dissent
Are the location services in settings clicked on? On SGS II ICS they are here : Settings>Locations services. The options in there must be clicked on.Dissent
i added the location service tab. plz refer that.Pongee
T
6

Finally i found the answer :https://code.google.com/p/android/issues/detail?id=38009

Reboot your device for Geocoder to work. Hope it helps someone

Note: some say it will work if you use Google API 16

Triviality answered 29/3, 2013 at 22:35 Comment(3)
This error was coming in Google Map API V1.. i have tried it on Google Map v2.. with some syntax change of course and it works might well on all android device. Note: For Google MAp V2 you no longer need to import Google APIsTriviality
In my app with V2 Map it doesn't work... What kind of import do you refer to?Blanketing
in the end it still doesn't work... even with API 16. how can I solve this problem?Blanketing
L
-2
  GeoPoint point = new GeoPoint(
                        (int) (LATITUDE * 1E6),
                        (int) (LONGITUDE * 1E6));

String n;

public void someRandomMethod() {
        n = convertPointToLocation(point);
}



public String convertPointToLocation(GeoPoint point) {
        String address = "";
        Geocoder geoCoder = new Geocoder(
                getBaseContext(), Locale.getDefault());
        try {
            List<Address> addresses = geoCoder.getFromLocation(
                    point.getLatitudeE6()  / 1E6,
                    point.getLongitudeE6() / 1E6, 1);

            if (addresses.size() > 0) {
                for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
                    address += addresses.get(0).getAddressLine(index) + " ";
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }

        return address;
    }
Luxate answered 28/3, 2013 at 23:35 Comment(1)
Please don't just provide code for your answer. Why is this is the answer?Americanism

© 2022 - 2024 — McMap. All rights reserved.