How to get complete address from latitude and longitude?

前端 未结 21 2440
深忆病人
深忆病人 2020-11-22 09:07

I want to get following values from Latitude and Longitude in android

  1. Street Address
  2. City / State
  3. Zip
  4. Complete Address
<
21条回答
  •  借酒劲吻你
    2020-11-22 09:31

    You need to pass the latitude and longitude value.

    Geocoder geocoder;
            List
    addresses; geocoder = new Geocoder(getContext(), Locale.getDefault()); try { addresses = geocoder. getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5 String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex() String city = addresses.get(0).getLocality(); String state = addresses.get(0).getAdminArea(); String country = addresses.get(0).getCountryName(); String postalCode = addresses.get(0).getPostalCode(); String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL System.out.println(address+"-------------"); } catch (IOException e) { e.printStackTrace(); }

提交回复
热议问题