项目中使用定位功能获取百度坐标,使用插件react-native-baidumap-sdk
https://github.com/qiuxiang/react-native-baidumap-sdk
问题一:安装好插件后,运行react-native run-android报错
* What went wrong:
The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher.
The following dependencies do not satisfy the required version:
project ':react-native-baidumap-sdk' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.41
解决方法:
重新安装,link
安装时使用react-native-baidumap-sdk@next这个版本
npm install react-native-baidumap-sdk@next
参考:
https://github.com/qiuxiang/react-native-baidumap-sdk/issues/164
问题二、
e: /Users/singcloud/Desktop/ReactNative/yunxiangsq/node_modules/react-native-baidumap-sdk/lib/android/src/main/java/cn/qiuxiang/react/baidumap/Utils.kt: (52, 56): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ReadableMap?
解决方法:
按照报错文件和报错位置修改文件
1、Utils.kt
fun ReadableArray.toLatLngList(): List<LatLng> {
return (0..(this.size() - 1)).map { this.getMap(it)!!.toLatLng() }
}
2、BaiduMapHeatMap.kt
val intensity = if (it!!.hasKey("intensity")) it!!.getDouble("intensity") else 0.0
3、BaiduMapView.kt
fun setStatus(args: ReadableArray?) {
val target = args!!.getMap(0)
val duration = args.getInt(1)
val mapStatusBuilder = MapStatus.Builder()
if (target!!.hasKey("center")) {
mapStatusBuilder.target(target!!.getMap("center")!!.toLatLng())
}
if (target!!.hasKey("zoomLevel")) {
mapStatusBuilder.zoom(target!!.getDouble("zoomLevel").toFloat())
}
if (target!!.hasKey("overlook")) {
mapStatusBuilder.overlook(target!!.getDouble("overlook").toFloat())
}
if (target!!.hasKey("rotation")) {
mapStatusBuilder.rotate(target!!.getDouble("rotation").toFloat())
}
if (target!!.hasKey("point")) {
val point = target!!.getMap("point")!!.toPoint()
mapStatusBuilder.target(map.projection.fromScreenLocation(point))
}
if (target!!.hasKey("region")) {
setStatus(MapStatusUpdateFactory.newLatLngBounds(
target!!.getMap("region")!!.toLatLngBounds()), duration)
} else {
setStatus(MapStatusUpdateFactory.newMapStatus(mapStatusBuilder.build()), duration)
}
}
4、其他文件就是这样改一下 就可以使用了
参考:
https://github.com/qiuxiang/react-native-baidumap-sdk/issues/179