How to get complete address from latitude and longitude?

前端 未结 21 2494
深忆病人
深忆病人 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:30

      Geocoder geocoder =new Geocoder(mContext, Locale.getDefault());
     // Get the current location from the input parameter list
      Location loc = params[0];
     // Create a list to contain the result address
      List
    addresses = null; try { addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 10); } catch (IOException e1) { Log.e("LocationSampleActivity","IO Exception in getFromLocation()"); e1.printStackTrace(); } catch (IllegalArgumentException e2) { // Error message to post in the log String errorString = "Illegal arguments " + Double.toString(loc.getLatitude()) + " , " + Double.toString(loc.getLongitude()) + " passed to address service"; Log.e("LocationSampleActivity", errorString); e2.printStackTrace(); } Address address=null; String zip=null; String city=null; String state=null; StringBuffer st=new StringBuffer(); // If the reverse geocode returned an address if (addresses != null && addresses.size() > 0) { String add=addresses.get(0).getAddressLine(0)+"," +addresses.get(0).getSubAdminArea()+"," +addresses.get(0).getSubLocality(); city=addresses.get(0).getLocality(); state=addresses.get(0).getAdminArea(); // Get the first address for(int i=0 ;i

提交回复
热议问题