2014-09-03 61 views

回答

0

使用這種方法

/** 
* Get list of address by latitude and longitude 
* @return null or List<Address> 
*/ 
public List<Address> getGeocoderAddress(Context context) 
{ 
    if (location != null) 
    { 
     Geocoder geocoder = new Geocoder(context, Locale.ENGLISH); 
     try 
     { 
      List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); 
      return addresses; 
     } 
     catch (IOException e) 
     { 
      //e.printStackTrace(); 
      Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e); 
     } 
    } 

    return null; 
} 

問候 行家

0

您可以使用以下方法 -

public String getLatLonByAddress(String addr) { 

     Geocoder geoCoder = new Geocoder(this); 
     List<Address> address = null; 

     try { 
      address = geoCoder.getFromLocationName(addr, 5); 
     } 
     catch (IOException e) { 
      e.printStackTrace(); 
     } 
     if (address == null) { 
      return null; 
     } 
     Address location = address.get(0); 

     return location.getLatitude() + "/" + location.getLongitude(); 
    }