0

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?

yoppie97
  • 117
  • 1
  • 18
  • i think this problem may be related to runtime permissions .you can try this (https://stackoverflow.com/questions/3574644/how-can-i-find-the-latitude-and-longitude-from-address) – abhinandan sharma Mar 12 '19 at 17:03
  • duplicated https://stackoverflow.com/questions/3574644/how-can-i-find-the-latitude-and-longitude-from-address – Nidhal Cherni Mar 12 '19 at 17:18

1 Answers1

0

Well first it's Eiffel Tower, not Paris Tower, I think you must submit an precise address, also make sure you have integrated the geocoding api library

benju
  • 116
  • 1
  • 8