如何解决 Android Place Autocomplete 意图问题?
我正在尝试在我的应用中使用 google 地点自动完成 。
正如文档中所述,有两种方法可以使用此功能:一种使用片段,另一种方法是使用 Intent,这就是我选择的方法。
我的代码如下所示
Gradle:
implementation 'com.google.android.libraries.places:places:2.5.0'
Kotlin:
第 1 部分
btn.setOnClickListener {
if (!Places.isInitialized()) {
Places.initialize(
requireActivity().applicationContext,
getString(R.string.google_maps_key)
)
}
@Suppress("DEPRECATION")
startActivityForResult(
Autocomplete
.IntentBuilder(
AutocompleteActivityMode.OVERLAY,
listOf(
Place.Field.ID,
Place.Field.NAME,
Place.Field.LAT_LNG,
Place.Field.ADDRESS,
Place.Field.ADDRESS_COMPONENTS
)
).build(requireContext()),
AUTOCOMPLETE_REQUEST_CODE
)
}
第 2 部分
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
when (resultCode) {
Activity.RESULT_OK -> {
data?.let {
val place = Autocomplete.getPlaceFromIntent(data)
Timber.i(TAG, "Place: ${place.name}, ${place.id}")
}
}
AutocompleteActivity.RESULT_ERROR -> {
// TODO: Handle the error.
data?.let {
val status = Autocomplete.getStatusFromIntent(data)
Timber.i(TAG, status.statusMessage)
}
}
Activity.RESULT_CANCELED -> {
// The user canceled the operation.
}
}
return
}
super.onActivityResult(requestCode, resultCode, data)
}
出现叠加层“放置自动完成”视图完美,但是当我尝试用胶带粘贴键盘来搜索某个地方时,视图崩溃而不是应用程序崩溃。只有视图,我收到以下错误(我不知道它是否相关):
set_timerslack_ns write failed: Operation not permitted
知道如何解决这个问题吗?
I'm trying to use google Place Autocomplete in my app.
Like described in the documentation, there is two ways to use this feature : one using a fragment and the other way is to use an Intent and that's what I choose.
My code is like below
Gradle:
implementation 'com.google.android.libraries.places:places:2.5.0'
Kotlin:
Part 1
btn.setOnClickListener {
if (!Places.isInitialized()) {
Places.initialize(
requireActivity().applicationContext,
getString(R.string.google_maps_key)
)
}
@Suppress("DEPRECATION")
startActivityForResult(
Autocomplete
.IntentBuilder(
AutocompleteActivityMode.OVERLAY,
listOf(
Place.Field.ID,
Place.Field.NAME,
Place.Field.LAT_LNG,
Place.Field.ADDRESS,
Place.Field.ADDRESS_COMPONENTS
)
).build(requireContext()),
AUTOCOMPLETE_REQUEST_CODE
)
}
Part 2
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
when (resultCode) {
Activity.RESULT_OK -> {
data?.let {
val place = Autocomplete.getPlaceFromIntent(data)
Timber.i(TAG, "Place: ${place.name}, ${place.id}")
}
}
AutocompleteActivity.RESULT_ERROR -> {
// TODO: Handle the error.
data?.let {
val status = Autocomplete.getStatusFromIntent(data)
Timber.i(TAG, status.statusMessage)
}
}
Activity.RESULT_CANCELED -> {
// The user canceled the operation.
}
}
return
}
super.onActivityResult(requestCode, resultCode, data)
}
The overlay 'Place Auto Complete' view appear perfectly but when I try to tape in the keyboard to search for some place, the view crashes not the app. only the view and I got the error below (I don't know if it is related) :
set_timerslack_ns write failed: Operation not permitted
Any idea how to solve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否“启用”了 api 密钥以使用 google 地点?
Did you "enable" your api key for using the google places?