我在 react-native-maps 上的版本 0.22.1 上,当我尝试使用 MapView 组件中的新animateCamera
方法时,它抱怨它是未定义的,不是函数,但已弃用的 animateToRegion
方法仍然有效。
animateCamera正在工作。我已经在我的项目中使用过,没有问题。
代码示例:
const mapRef = useRef(null);
useEffect(() => {
if (mapRef.current) {
mapRef.current.animateCamera({
center: {latitude, longitude},
});
}
},[currentPosition]);
<MapView
ref={mapRef}
style={styles.mapContainer}
initialRegion={{
...currentPosition,
latitudeDelta: 0.001,
longitudeDelta: 0.001,
}}
>
<Marker coordinate={currentPosition} />
</MapView