2017-10-08 15 views
0

コンポーネントのレンダリング直後にマップ上のメソッドを呼び出そうとしています。この場合、this.mapは未定義ですが、refで設定しないでください。 componentDidMountメソッドでMapViewへの参照を取得するにはどうすればよいですか?このGithub issueを見るとリアクションネイティブマップは、最初のレンダリングの後にベアリングにアニメーションされます

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, 
     }} 
     /> 
    ); 
    } 
} 

答えて

1

、あなたはおそらくonLayoutの代わりcomponentDidMountを使用する必要があります。例えば

<MapView 
    ref={ref => { this.map = ref }} 
    onLayout={() => this.map.animateToBearing(25)} 
    .... 
/> 
+0

私はまだ_this2.map.animateToBearingあなたは[ 'airbnb /反応し、ネイティブ・'からMapView'をしようとした場合どのようなpjb3 @機能 – pjb3

+0

ないというエラーを取得していますmaps'](https://github.com/airbnb/react-native-maps)?おそらく、 'expo'にバンドルされている' MapView'は古いバージョンです – Bill

関連する問題