源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-09-03 04:18 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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());
    }
    // }
  }

运行效果如下图所示: [img]http://files.jb51.net/file_images/article/201507/2015721100427998.png?201562110451[/img] 希望本文所述对大家的Android程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部