本文實例講述了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程序設計有所幫助。
新聞熱點
疑難解答
圖片精選