Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Geocode for java #310

Open
panjisadewo opened this issue Oct 18, 2022 · 1 comment
Open

Geocode for java #310

panjisadewo opened this issue Oct 18, 2022 · 1 comment

Comments

@panjisadewo
Copy link

I try geocode but i has error like this.
java.io.IOException: Service not Available
2022-10-18 12:30:10.785 4101-4101/? W/System.err: at android.location.Geocoder.getFromLocationName(Geocoder.java:178)

This is my code

    Geocoder geocoder = new Geocoder(getContext(), Locale.getDefault());
    List<Address> addresses;;
    try {
        addresses = geocoder.getFromLocation(-6.193479061, 106.848579406, 10);
        if(addresses.size() > 0){
            String cityName = addresses.get(0).getCountryName();
            String stateName = addresses.get(0).getAddressLine(1);
            String countryName = addresses.get(0).getAddressLine(2);
            Toast.makeText(getActivity(), addresses.size(), Toast.LENGTH_LONG);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
@SweetD3v
Copy link

SweetD3v commented Jul 3, 2023

You need to check if the service is available or not on the device like this,

if (GeoCoder.isPresent()) {
    //TODO Get the address
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants