实现 Geocoder 时返回 null
我正在尝试使用地理编码器查找地址(位置)。
我有以下代码:
double lat = (double) (coord.getLat() * (1e-6));
double lon = (double) (coord.getLon() * (1e-6));
try {
List<Address> list = geocoder.getFromLocation(lat, lon,1);
if (list != null && list.size() > 0) {
Address address = list.get(0);
result = address.getAddressLine(0) + ", "
+ address.getLocality();
}
System.out.println("adresa returnata folosind geocoder:"
+ result);
}
我传递给地理编码器的数据采用以下格式:
2.449548 48.950518
但是,当尝试 println()
Geocoder 返回的第一个地址时,它返回 null。这就是我的 logcat 的样子:
reverseGeocode()`:没有功能 G位置
我的 System.out.println()
显示 :null
。我有互联网接入,并且互联网权限已添加到我的清单文件中。有人知道我做错了什么吗?
I'm trying to find the address(location) using Geocoder.
I have the following code:
double lat = (double) (coord.getLat() * (1e-6));
double lon = (double) (coord.getLon() * (1e-6));
try {
List<Address> list = geocoder.getFromLocation(lat, lon,1);
if (list != null && list.size() > 0) {
Address address = list.get(0);
result = address.getAddressLine(0) + ", "
+ address.getLocality();
}
System.out.println("adresa returnata folosind geocoder:"
+ result);
}
The data that I pass to geocoder is in this format:
2.449548
48.950518
But when trying to println()
the first address returned by Geocoder it returns null. This is how my logcat looks like:
reverseGeocode()`: no feature in
GLocation
And my System.out.println()
displays :null
. I have internet acces and also internet permssion added to my manifest file. Does someone know what I'm doing wrong??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Geobits 所说,你的坐标属于阿拉伯海的地方。您无法从那里获取地址,因此您的列表为空,结果为空。
As Geobits said, your coordinates belong to place in the Arabian Sea. You cant get an Address from there, so your list is empty and your result is null.