【发布时间】:2017-10-08 00:25:55
【问题描述】:
我试图在组件首次呈现后立即在地图上调用一个方法。在这种情况下,this.map 是未定义的,但它不应该由 ref 设置吗?如何在 componentDidMount 方法中获取对 MapView 的引用?
import React from 'react';
import { MapView } from 'expo';
export default class Map extends React.Component {
componentDidMount() {
this.map.animateToBearing(25)
}
render() {
return (
<MapView
ref={ref => { this.map = ref }}
style={{ flex: 1 }}
mapType="satellite"
initialRegion={{
latitude: 39.2741004,
longitude: -76.6502307,
latitudeDelta: 0.002,
longitudeDelta: 0.001,
}}
/>
);
}
}
【问题讨论】:
标签: react-native react-native-maps