开发者

error in implementing the geocoder

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开发者_如何学Python(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);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜