gpt4 book ai didi

android - Kotlin转换为Double?加倍

转载 作者:行者123 更新时间:2023-12-02 12:32:29 26 4
gpt4 key购买 nike

我正在使用Mapbox开发 map 应用程序。
我正在使用的方法使用Point(Double,Double)
获取类型不匹配要求:两次发现:两次?

        val lat = locationComponent.lastKnownLocation?.latitude?.toDouble()
val lng = locationComponent.lastKnownLocation?.latitude?.toDouble()
origin = Point.fromLngLat(lat, lng)

最佳答案

您可以使用!!将其“强制”为不可为空的值,也可以提供“如果为空值”。
使用 !!:

val lat = locationComponent.lastKnownLocation?.latitude?.toDouble()
val lng = locationComponent.lastKnownLocation?.latitude?.toDouble()
origin = Point.fromLngLat(lat!!, lng!!)
使用默认值:
val lat = locationComponent.lastKnownLocation?.latitude?.toDouble()
val lng = locationComponent.lastKnownLocation?.latitude?.toDouble()
origin = Point.fromLngLat(lat?: 0.0, lng?: 0.0)

关于android - Kotlin转换为Double?加倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64376040/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com