android通过Location API显示地址信息 android通过Location API显示地址信息的实现方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

android通过Location API显示地址信息 android通过Location API显示地址信息的实现方法

华宰   2021-03-21 我要评论
想了解android通过Location API显示地址信息的实现方法的相关内容吗,华宰在本文为您仔细讲解android通过Location API显示地址信息的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:android,Location,API,地址信息,下面大家一起来学习吧。

本文实例讲述了android通过Location API显示地址信息的实现方法。分享给大家供大家参考。具体如下:

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

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

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());
    }
    // }
  }

运行效果如下图所示:

希望本文所述对大家的Android程序设计有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们