可能重复:
如何从纬度和经度获得完整的地址?
如何使用纬度和经度在 Android 中获取位置名称,直到城市名称和街道名称
尝试这个
private void getAddressGoogleQuery() {
String address = "";
try {
String URL = "http://maps.google.com/maps/geo?q=" + latitude + ","
+ longitude + "&output=csv";
String device_address = Get(URL);
String[] output = device_address.split("\"");
try {
address = output[1];
} catch (Exception e) {
// TODO: handle exception
}
Log.d("Activity", "Address:" + address);
} catch (Exception e) {
}
}
public static String Get(String URLStr) throws Exception
{
String resultStr = "";
BufferedReader in = null;
try
{
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(URLStr);
HttpResponse response = client.execute(request);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
resultStr = sb.toString();
}
catch(Exception ee)
{
ee.printStackTrace();
}
finally
{
if (in != null)
{
try
{
in.close();
} catch (Exception e)
{
}
}
}
return resultStr;
}
您可以使用反向地理编码器来实现它。一个示例代码:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(latValue,
longValue, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder(
"Address:\n");
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress
.append(returnedAddress.getAddressLine(i)).append(
"\n");
}
myAddress.setText(strReturnedAddress.toString());
} else {
myAddress.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
myAddress.setText("Canont get Address!");
}
只需在获得纬度和经度值后放置此代码。
您可以使用Geocoder类来获取城市和国家信息等信息。
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1);