如果我们在Android中使用location API提供纬度和经度,如何获取地址

如果我们在Android中使用location API提供纬度和经度,如何获取地址,android,android-widget,Android,Android Widget,我有一个应用程序,其中我尝试根据纬度、经度坐标获取一个位置的地址。当我尝试打印特定坐标的所有地址时,我只得到一个地址。是否有任何方法可以获取所提供坐标的所有地址列表。我的代码片段如下所示: 其中locationLatitude、LocationLength为转换为双精度的字符串类型 ****列表地址=geoCoder.getFromLocation(双精度) .parseDouble(位置纬度),Double.parseDouble(位置经度),1); StringBuffer addressA

我有一个应用程序,其中我尝试根据纬度、经度坐标获取一个位置的地址。当我尝试打印特定坐标的所有地址时,我只得到一个地址。是否有任何方法可以获取所提供坐标的所有地址列表。我的代码片段如下所示:

其中locationLatitude、LocationLength为转换为双精度的字符串类型

****列表地址=geoCoder.getFromLocation(双精度) .parseDouble(位置纬度),Double.parseDouble(位置经度),1); StringBuffer addressAsString=新的StringBuffer(“”); 如果(!addresses.isEmpty()){ for(int i=0;i 我将等待任何答复。
提前感谢。

您必须仔细阅读api:

公共方法 列表getFromLocation(双纬度、双经度、int-maxResults)

返回一个已知的地址数组,用于描述给定纬度和经度周围的区域

如果将maxResults参数从1更改为10,则如果有,将返回10个结果

List addresses = geoCoder.getFromLocation(Double .parseDouble(locationLatitude), Double.parseDouble(locationLongitude), 10); 

循环浏览您的所有地址:

List addresses = geoCoder.getFromLocation(Double .parseDouble(locationLatitude), Double.parseDouble(locationLongitude), 10); 

for (Address addr:List addresses) {

  for (int i = 0; i < addr.getMaxAddressLineIndex(); i++) {
  // your previous code here
  }
}
List addresses=geoCoder.getFromLocation(Double.parseDouble(locationLatitude),Double.parseDouble(locationLatitude),10);
用于(地址地址:列出地址){
对于(int i=0;i
请将代码格式化为易于阅读的代码。是的,没错。但他甚至还没有遍历“地址”,尽管他已经将其定义为列表。