简体   繁体   English

如何在Android模拟器中使用经度和纬度获取完整的地方地址?

[英]how to get complete place address using latitude and longitude on emulator in android?

This is my code It don't have any error but 这是我的代码,没有任何错误,但是

It shows in textView "No Address returned!" 它在textView中显示“未返回地址!”

double lat = 18.520430300000000000, log = 73.856743699999920000;
    String address = null;                                                 
    Geocoder geocoder = new Geocoder(this, Locale.getDefault());
    StringBuilder sb = null;
    try {
        List<Address> addresses = geocoder.getFromLocation(lat, log, 1); 
        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)+ ",");
           txtAdd.setText("Address :"+sb);
        }
        else{
            txtAdd.setText("No Address returned!");
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        /*e.printStackTrace();*/
        txtAdd.setText("Canont get Address!");
    }

Plz give me solution on this 请给我解决方案

Thanks in Advance... 提前致谢...

The doku gives one hint, maybe this should help Doku给出了一个提示,也许这应该有所帮助

http://developer.android.com/reference/android/location/Geocoder.html http://developer.android.com/reference/android/location/Geocoder.html

Returns an array of Addresses that are known to describe the area immediately surrounding the given latitude and longitude. 返回一个地址数组,该地址已知可描述紧接给定纬度和经度的区域。 The returned addresses will be localized for the locale provided to this class's constructor. 返回的地址将针对提供给此类的构造函数的语言环境进行本地化。

The returned values may be obtained by means of a network lookup. 可以通过网络查找获得返回的值。 The results are a best guess and are not guaranteed to be meaningful or correct. 结果是最佳猜测,不能保证是有意义或正确的。 It may be useful to call this method from a thread separate from your primary UI thread. 从与主UI线程分开的线程中调用此方法可能很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM