Android

Android 經緯度轉地址

Android 經緯度轉地址

文章目錄

  1. 創建Geocoder
  2. 取出地址

1.創建Geocoder

//把經緯度放進去
val addresses = Geocoder(this, Locale.getDefault())
    .getFromLocation(latitude, longitude, 1)

//取得第一個資料
val address = addresses[0]

2.取出地址

//整串地址(110台灣台北市信義區信義路五段5號2C20室)
Log.d("DATA", address.getAddressLine(0))
//(110)
Log.d("DATA", address.postalCode)
//(台灣)
Log.d("DATA", address.countryName)
//(台北市)
Log.d("DATA", address.adminArea)
//(信義區)
Log.d("DATA", address.locality)
//(信義路五段)
Log.d("DATA", address.thoroughfare)
//(5號)
Log.d("DATA", address.featureName)

發表迴響