Android 4.1.2 and geocoder

110 Views Asked by At

I need to use google geocoder to display an address from gps coordinates in my app.

The fact is that I get an error like : "unable to parse response from the server" in my app.

It seems, after some documentation, that it's due to Android 4.1.2.

Question

I need to know, if there was any way to encounter this and get addresses from gps coordinates ?

Here's my actual code that throw me the error :

public String[] reverseGeocoding(Double latitude, Double longitude) {
    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    String[] adress = new String[3];
    try {
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
        Log.e("ADRESSE SIZE", addresses.size() + "");
        if (addresses.size() > 0) {
            Address address = addresses.get(0);

            adress[0] = address.getAddressLine(0);
            adress[1] = address.getLocality();
            adress[2] = address.getPostalCode();
        }
    } catch (IOException e) {
        e.printStackTrace();
        adress[0] = adress[1] = adress[2] = null;
    }

    return adress;
}
0

There are 0 best solutions below