【问题标题】:No PlaceSelectionListener is set. No result will be delivered未设置 PlaceSelectionListener。没有结果将被交付
【发布时间】:2019-11-06 10:19:29
【问题描述】:

当我点击autocompletefragment 时。日志显示:

地点:未设置 PlaceSelectionListener。不会有结果 已送达。

val realView = inflater.inflate(R.layout.fragment_connect, container, false)

Places.initialize(activity!!.applicationContext, getString(R.string.google_maps_key))
val placesClient = Places.createClient(activity!!)

val autocompleteFragment1 = fragmentManager?.findFragmentById(R.id.autocomplete_fragment1) as? AutocompleteSupportFragment // Make casting of 'as' to nullable cast 'as?'

autocompleteFragment1?.setCountry("PH")
// Specify the types of place data to return.
autocompleteFragment1?.setPlaceFields(listOf(Place.Field.ID, Place.Field.NAME))

// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment1?.setOnPlaceSelectedListener(object : PlaceSelectionListener {
    override fun onPlaceSelected(place: Place) {
        Log.d("Hey", place.toString())
    }

    override fun onError(status: Status) {
        // TODO: Handle the error.
        Log.d("HOY", "An error occurred: ${status.statusCode}")
    }
})

【问题讨论】:

    标签: android google-maps kotlin googleplacesautocomplete


    【解决方案1】:

    您正在使用已弃用的代码。尝试替换此行:

    val autocompleteFragment1 = fragmentManager?.findFragmentById(R.id.autocomplete_fragment1) as? AutocompleteSupportFragment // Make casting of 'as' to nullable cast 'as?'
    

    有了这个:

    val autocompleteFragment1 = supportFragmentManager.findFragmentById(R.id.autocomplete_fragment1) as? AutocompleteSupportFragment // Make casting of 'as' to nullable cast 'as?
    

    在进行上述更改后,您的确切代码对我有用,所以我希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2018-03-15
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-01-14
      • 2014-11-01
      • 1970-01-01
      • 2020-01-05
      相关资源
      最近更新 更多