简体   繁体   中英

How to convert keyword into Latitude Longitude Google Maps [Android]

From backend, I get field address "Paris Tower". And I wan to show maps with marker(at Paris Tower). So, I need LatLng for show maps. I've tried using GeoCoder, but it's always null.

fun location(address: String) {
var addressList: List<Address> = listOf()
val geoCoder = Geocoder(this)
try {
  addressList = geoCoder.getFromLocationName("Candi Prambanan", 1)
} catch (e: IOException) {
  e.printStackTrace()
}
Log.d("Test addressList", addressList.toString())
if (addressList.isNotEmpty()) {
  val addressLoc = addressList[0]
  val latLng = LatLng(addressLoc.latitude, addressLoc.longitude)
  this.lat = addressLoc.latitude.toString()
  this.long = addressLoc.longitude.toString()
}

}

How should I do?

首先是艾菲尔铁塔,而不是巴黎铁塔,我想您必须提交准确的地址,并确保已集成地理编码api库

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM