从后端,我获得字段地址“巴黎铁塔”。我想显示带有标记的地图(在巴黎铁塔上)。因此,我需要LatLng来显示地图。我尝试使用GeoCoder,但始终为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()
}
}
我应该怎么办?