无法实现反向地址解析 [英] Couldn't achieve Reverse Geocoding
问题描述
我的工作的GPS系统为Android。我能找到我的当前位置的经度和纬度,但是当我尝试我的经纬度转换成物理地址,我的code不起作用。我已经尝试了几种可能性。我已经张贴在这里我的code。
任何帮助很多AP preciated。
谢谢你。
{尝试 清单<地址>地址= gc.getFromLocation(纬度,经度,1);
的System.out.println(+纬度);
StringBuilder的SB =新的StringBuilder();
如果(addresses.size()大于0){ 地址地址= addresses.get(0);
的for(int i = 0; I< address.getMaxAddressLineIndex();我++)
。sb.append(address.getAddressLine(I))追加(\\ n);
。sb.append(address.getLocality())追加(\\ n);
。sb.append(address.getPostal code())追加(\\ n);
sb.append(address.getCountryName());
}
addressString = sb.toString();
}赶上(IOException异常五){}
}其他{
latLongString =没有发现地点;
}
myLocationText.setText(您当前的位置为:\\ n+
latLongString +\\ n+ addressString);
}
我的问题是,我不能让任何值列表与LT;地址>地址= gc.getFromLocation(纬度,经度,1);
。它只返回一个空列表。
谁能告诉我是什么问题以及如何梳理出来......
地理codeR GC =新的地缘codeR(CTX,Locale.getDefault());
清单<地址>地址;
地址= gc.getFromLocation(纬度,经度,1);
StringBuilder的SB =新的StringBuilder();
如果(addresses.size()大于0)
{
地址地址= addresses.get(0);
的for(int i = 0; I< address.getMaxAddressLineIndex();我++)
sb.append(address.getAddressLine(i))的附加(,);
}
这会得到一个位置。但有时一个例外当属无法解析来自服务器的响应
。您需要处理exception.Also检查清单中的 INTERNET权限
。
I am working on GPS system for android. I am able to find the latitude and longitude of my current position, but when I try to convert my latitude and longitude into Physical address my code doesn't work. I have tried several possibilities. I have posted my code here.
Any help is much appreciated. Thanks.
try {
List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
System.out.println(""+latitude);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
} catch (IOException e) {}
} else {
latLongString = "No location found";
}
myLocationText.setText("Your Current Position is:\n" +
latLongString + "\n" + addressString);
}
My problem is, I couldn't get any value in the List<Address> addresses = gc.getFromLocation(latitude, longitude, 1);
. It returns a empty list only.
Could anyone tell me what the problem is and how to sort it out...
Geocoder gc = new Geocoder(ctx, Locale.getDefault());
List<Address> addresses;
addresses = gc.getFromLocation(lat, lng, 1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0)
{
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
sb.append(address.getAddressLine(i)).append(",");
}
This would get a location. But sometimes an exception comes as "Unable to parse the response from server"
. You need to handle the exception.Also check for the INTERNET permission
in the manifest.
这篇关于无法实现反向地址解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!