本文實(shí)例講述了android通過Location API顯示地址信息的實(shí)現(xiàn)方法。分享給大家供大家參考。具體如下:
android的Locatin API,可以通過Geocoder類,顯示具體經(jīng)緯度的地址信息。如:
通過Geocoder的方法getFromLocation()可以得到Address對(duì)象的List。我只取一個(gè)Address結(jié)果,可以取多個(gè),但是意義不大。
StringBuilder builder = new StringBuilder();builder.append("北緯:").append(this.location.getLatitude()).append("/n");builder.append("東經(jīng):").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()); } // } }運(yùn)行效果如下圖所示:

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選