React Native MapView:通过相机方向旋转地图

5

我正在尝试在React Native的<MapView>中旋转地图,但没有找到如何根据相机方向旋转地图的描述。教程说明:

当将此属性设置为true并且地图关联有效相机时,相机的朝向角度会用于围绕地图中心点旋转地图平面。

因此,我已经达到了以下步骤:

<MapView
          style={styles.map}
          onRegionChange={this._onRegionChange}
          onRegionChangeComplete={this._onRegionChangeComplete}
          region={this.state.mapRegion}
          annotations={this.state.annotations}
          rotateEnabled={true}

但是关于相机如何与地图相关联,没有任何解释。

请问有人可以帮忙解决这个问题吗?

2个回答

0

你可以使用animateCamera

const mapRef = useRef(null);

  const animate_point=async()=>{
      mapRef.current.animateCamera({
        heading:60,
        zoom: 17,
        center: {
          latitude:latitude_coordinate,
        longitude:longitude_coordinate ,
    },
    pitch: 45,})
 
  } ->pass this function whenever you want. like in onRegionChange function

 <MapView
        ref={mapRef}
onRegionChange={animate_point}

-2
使用相机属性来实现这个功能。
你可以阅读文档以获取更多信息。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接