因此,我尝试使用geocoder.getFromLocationName()在kotlin中将文本地址转换为坐标。
import android.location.Geocoder
val geocoder = Geocoder(context, Locale.getDefault())
try {
val result = geocoder.getFromLocationName(club.location, 1) // it gets hung here before throw!!
Log.d(LOG_TAG, "${club.location} translates into cordinates : ${result[0].latitude}, ${result[0].longitude}")
}
catch (ex : Exception){
Log.d(LOG_TAG, "${ex.message}")
}
但它总是抓住例外说
Caused by: java.io.IOException: DEADLINE_EXCEEDED: ClientCall started after deadline exceeded: -15.077367176s from now
at android.location.Geocoder$SynchronousGeocoder.getResults(Geocoder.java:388)
at android.location.Geocoder.getFromLocationName(Geocoder.java:277)
at android.location.Geocoder.getFromLocationName(Geocoder.java:202)
android中的地理编码器不工作吗?很难相信..。还是我错过了什么?
我试着上网查,但没有找到有用的答复。
发布于 2022-11-18 23:19:48
好吧,似乎模拟器不适用于地理编码器的使用,但真正的物理设备工作
https://stackoverflow.com/questions/74415562
复制相似问题