PlaceAutocomplete小部件在Android 4.1

时间:2016-04-25 20:39:31

标签: android google-maps kotlin

PlaceAutocomplete widget在Android 5.0中运行良好,但在调用openAutocomplete时4.1没有任何反应。 LogCat中没有错误。 onActivityResult已执行,但在数据参数中为null。有什么问题?

代码:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if (requestCode == 1) {
        if (resultCode == FragmentActivity.RESULT_OK) {
            val place = PlaceAutocomplete.getPlace(activity, data)

            val cameraUpdate = CameraUpdateFactory.newLatLng(place.latLng)
            // map.moveCamera(cameraUpdate)
            map.animateCamera(cameraUpdate)

            if (action === AddressPickerType.FROM) {
                activity.order.from.onNext(place)
            } else {
                activity.order.to.onNext(place)
            }
        }
        else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            val status = PlaceAutocomplete.getStatus(activity, data)
            Log.e(App.tag, "Error: Status = " + status.toString())
        }
        else if (resultCode == FragmentActivity.RESULT_CANCELED) {}
    }
}

fun openAutocomplete() {
    val intent = PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
        .build(activity)

    try {
        startActivityForResult(intent, 1)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

P.S。抱歉我的英文

0 个答案:

没有答案