Geocoder gc = new Geocoder(getActivity(), Locale.TRADITIONAL_CHINESE);
List<Address> lstAddress = gc.getFromLocation(lat, lng, 1);
String returnAddress=lstAddress.get(0).getAddressLine(0);
取地的結果會是全部的地址,如:100台灣台北市中正區信陽街33號
但取得的是全部的地址,但如果只是想取得城市等等,所以這邊自己記錄一下。
lstAddress.get(0).getCountryName(); //台灣省
lstAddress.get(0).getAdminArea(); //台北市
lstAddress.get(0).getLocality(); //中正區
lstAddress.get(0).getThoroughfare(); //信陽街(包含路巷弄)
lstAddress.get(0).getFeatureName(); //會得到33(號)
lstAddress.get(0).getPostalCode(); //會得到100(郵遞區號)
20121115補充:
也可以使用Json抓取資料後再顯示在Android上
網址為:
http://ditu.google.com/maps/geo?q=您的Latitude,您的Longitude&output=可以json或xml&oe=utf8&hl=zh-CN&sensor=true&key=您的Map APIkey
這樣我會得到以下內容,再對照取出也可以。
{ "name": "25.03078,121.442786", "Status": { "code": 200, "request": "geocode" }, "Placemark": [ { "id": "p1", "address": "242台灣新北市新莊區新莊路751巷83號", "AddressDetails": { "Accuracy" : 8, "Country" : { "AdministrativeArea" : { "AdministrativeAreaName" : "新北市", "Locality" : { "DependentLocality" : { "DependentLocalityName" : "國泰裡", "PostalCode" : { "PostalCodeNumber" : "242" }, "Thoroughfare" : { "ThoroughfareName" : "新莊路751巷83號" } }, "LocalityName" : "新莊區" } }, "CountryName" : "台灣", "CountryNameCode" : "TW" } }, "ExtendedData": { "LatLonBox": { "north": 25.0320820, "south": 25.0293840, "east": 121.4441770, "west": 121.4414790 } }, "Point": { "coordinates": [ 121.4428280, 25.0307330, 0 ] } } ] }