ios 调用 moveCamera 闪退,在 Android 则好的。
const [location, setLocation] = useState<LocationType>({
longitude: 0,
latitude: 0
})
const mapRef = useRef(null)
const queryLocation = async () => {
try {
const [longitude, latitude] = await getLocation()
mapRef.current?.moveCamera({
target: { longitude, latitude },
zoom: 12
}, 100)
setLocation({ longitude, latitude })
} catch (error) {
console.log('location.error', error);
}
}
useEffect(() => {
queryLocation()
}, [])
return (
<MapView
ref={mapRef}
style={styles.mapContainer}
// compassEnabled={false}
// zoomControlsEnabled={false}
// scaleControlsEnabled={false}
// myLocationEnabled={true}
// myLocationButtonEnabled={true}
// zoomGesturesEnabled={false}
// scrollGesturesEnabled={false}
// rotateGesturesEnabled={false}
// initialCameraPosition={{
// target: location,
// zoom: 16,
// }}
minZoom={14}
>
</MapView>
)
const styles = StyleSheet.create({
mapContainer: {
// flex: 1,
width: width,
height: 300,
}
})
在 Android 上没问题,到了 IOS 真机上就闪退,如果把moveCamera 注释掉就没问题,代码如上。
mapRef.current?.moveCamera({
target: { longitude, latitude },
zoom: 12
}, 100) // 100 改成 5000,就 5s 后闪退。
有这个问题的,不过之前RN的项目是0.72的记得是没问题的,后面升级到了0.76也就有这个问题了
同样问题,解决了吗?
"react-native": "0.79.2", "react-native-amap-geolocation": "^1.2.3", "react-native-amap3d": "^3.2.4",
默认安装完编译报错,更新 AMap3DMap ~> 10.0.600 后编译成功了, 但,点击moveCamera报错
同样的问题有解决方案吗?
在MapViewManager.swift文件中
将AMapViewManager中的getView方法改成如下
func getView(reactTag: NSNumber, callback: @escaping (MapView) -> Void) {
// 注释掉下面代码
// bridge.uiManager.addUIBlock { _, viewRegistry in
// callback(viewRegistry![reactTag] as! MapView)
// }
// 改成如下代码
// 首先获取当前的view
let currentView = bridge.uiManager.view(forReactTag: reactTag)
// 判断currentView是否为MapView
if currentView is MapView {
// callback(currentView as! MapView)
bridge.uiManager.addUIBlock { _, viewRegistry in
callback(currentView as! MapView)
}
} else {
print("AMapViewManager, currentView is not MapView")
}
}
我是这样解决的
我们这边是直接 将源码拉下来,然后换RN 新的侨接方式重写的
------------------ 原始邮件 ------------------ From: xiaobaidechengzhang @.> 发送时间: 08/26/2025, 17:09 To: qiuxiang/react-native-amap3d @.> 抄送: sunshine8624 @.>, Comment @.> Subject: Re: [qiuxiang/react-native-amap3d] ios 调用 moveCamera 闪退,在 Android 则好的。 (Issue #847)
xiaobaidechengzhang left a comment (qiuxiang/react-native-amap3d#847)
在MapViewManager.swift文件中
将AMapViewManager中的getView方法改成如下
func getView(reactTag: NSNumber, callback: @escaping (MapView) -> Void) { // 注释掉下面代码 // bridge.uiManager.addUIBlock { _, viewRegistry in // callback(viewRegistry![reactTag] as! MapView) // } // 改成如下代码 // 首先获取当前的view let currentView = bridge.uiManager.view(forReactTag: reactTag) // 判断currentView是否为MapView if currentView is MapView { // callback(currentView as! MapView) bridge.uiManager.addUIBlock { _, viewRegistry in callback(currentView as! MapView) } } else { print("AMapViewManager, currentView is not MapView") } }
我是这样解决的
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
我们这边是直接 将源码拉下来,然后换RN 新的侨接方式重写的 …
能分享下吗?
刚开始,还在弄
------------------ 原始邮件 ------------------ From: xiaobaidechengzhang @.> 发送时间: 08/26/2025, 17:40 To: qiuxiang/react-native-amap3d @.> 抄送: sunshine8624 @.>, Comment @.> Subject: Re: [qiuxiang/react-native-amap3d] ios 调用 moveCamera 闪退,在 Android 则好的。 (Issue #847)
xiaobaidechengzhang left a comment (qiuxiang/react-native-amap3d#847)
我们这边是直接 将源码拉下来,然后换RN 新的侨接方式重写的 …
能分享下吗?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>