欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

android通过Location API显示地址信息,androidlocation

来源: 开发者 投稿于  被查看 37845 次 评论:34

android通过Location API显示地址信息,androidlocation


android的Locatin API,可以通过Geocoder类,显示具体经纬度的地址信息。如:

通过Geocoder的方法getFromLocation()可以得到Address对象的List。我只取一个Address结果,可以取多个,但是意义不大。

1.[Java]代码

StringBuilder builder = new StringBuilder();
builder.append("北纬:").append(this.location.getLatitude()).append("\n");
builder.append("东经:").append(this.location.getLongitude()).append("\n");
try {
    List<Address> addresses = new Geocoder(this).getFromLocation(
            this.location.getLatitude(), this.location.getLongitude(),
            3);
    if (addresses.size() > 0) {
        Address address = addresses.get(0);
        // for (Address address : addresses) {
        for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
            builder.append(address.getAddressLine(i)).append("\n");
            // builder.append(address.getLocality()).append("\n");
            // builder.append(address.getPostalCode()).append("\n");
            // builder.append(address.getCountryName());
        }
        // }
    }

2.[图片] image_thumb27.png

用户评论