实施地理编码器时出错
我试图以这种方式在类中实现地理编码器:
Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
List<Address> list = geocoder.getFromLocation(
(double)(coord.getLat()), (double)(coord.getLon()), 1);
if (list != null && list.size()>0 ) {
Address address=list.get(0);
String result = address.getAddressLine(0) + ", " + address.getLocality();
}
我传递给 getLocationFrom() 的纬度和经度是以下形式的整数:
getFromLocation() 中的 2365818 48930308 我将其转换为 double 。
无论如何,我的应用程序在这一行阻塞:
List<Address> list = geocoder.getFromLocation(
(double)(coord.getLat()), (double)(coord.getLon()), 1);
抛出以下内容:
java.lang.IllegalArgumentException: latitude == 2365818.0
at android.location.Geocoder.getFromLocation(Geocoder.java:114)
at android.location.Geocoder.getFromLocation(Geocoder.java:124)
at com.Server_1.ClientThread_special.run(ClientThread_special.java:70) 在 java.lang.Thread.run(Thread.java:1096)
ClientThread_special 中的第 70 行表示这一行:
List<Address> list = geocoder.getFromLocation(lat, lon,1);
I'm trying to implement a Geocoder in a class this way:
Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
List<Address> list = geocoder.getFromLocation(
(double)(coord.getLat()), (double)(coord.getLon()), 1);
if (list != null && list.size()>0 ) {
Address address=list.get(0);
String result = address.getAddressLine(0) + ", " + address.getLocality();
}
The latitude and longitude that I pass to the getLocationFrom() is integer in this form:
2365818 48930308 in the getFromLocation() I cast it to double .
Anyway my app blocks at this line:
List<Address> list = geocoder.getFromLocation(
(double)(coord.getLat()), (double)(coord.getLon()), 1);
throwing the following:
java.lang.IllegalArgumentException: latitude == 2365818.0
at android.location.Geocoder.getFromLocation(Geocoder.java:114)
at android.location.Geocoder.getFromLocation(Geocoder.java:124)
at com.Server_1.ClientThread_special.run(ClientThread_special.java:70)
at java.lang.Thread.run(Thread.java:1096)
Line 70 in ClientThread_special means this line:
List<Address> list = geocoder.getFromLocation(lat, lon,1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getFormLocation 的纬度不会低于 -90 或超过 90。长可能是 -180 到 180。这些是地球上的角度,你的值太高了。
请参阅 Geocoder 文档
尝试将这些值除以 100000 以将它们转换为正确的双精度值。
更新:
对于您必须分配的金额,我可能是错误的。也尝试 1000000 (1M)
getFormLocation does not take lat below -90 or over 90. Long might be -180 to 180. Those are angle-degrees on the globe and your values are way to high.
See Geocoder Docs
Try to divide the values by 100000 to convert them to proper double-values.
UPDATE:
I might have been wrong regarding the amount you have to devide by. Try 1000000 (1M) aswell