如何使用纬度和经度在Android中获取位置名称[重复]
Posted
技术标签:
【中文标题】如何使用纬度和经度在Android中获取位置名称[重复]【英文标题】:How to get location name in Android using Lattitude and Longitude [duplicate] 【发布时间】:2013-01-11 11:34:07 【问题描述】:可能重复:How to get complete address from latitude and longitude?
如何在 android 中使用纬度和经度获取位置名称,直到城市名称和街道名称
【问题讨论】:
看***.com/questions/9409195/… 【参考方案1】:试试这个
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;
【讨论】:
非常感谢您的回复。它解决了我的问题 不客气。请将其标记为答案。【参考方案2】:您可以使用反向geocoder 来实现它。一个示例代码:
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!");
只需在获得纬度和经度值后放置此代码即可。
【讨论】:
【参考方案3】:您可以使用Geocoder 类获取城市和国家信息等信息。
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1);
【讨论】:
以上是关于如何使用纬度和经度在Android中获取位置名称[重复]的主要内容,如果未能解决你的问题,请参考以下文章
如果我们在 Android 中使用位置 API 给出纬度和经度,如何获取地址