我需要將地圖添加到我的應用程序中,因爲谷歌地圖 當我從輸入或任何地方選擇地點時,由於此選擇而在地圖上顯示地圖或過濾組件, 我確實需要的是通過本機反應在我的應用程序上啓動地圖。 我嘗試使用這個插件 https://www.npmjs.com/package/react-native-maps通過反應原生地圖添加地圖
安裝此npm install react-native-maps --save
但它給我的錯誤
class App extends Component {
constructor(props) {
super(props);
this.state = {
region: this.getInitialState()
};
}
getInitialState() {
return {
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
};
}
onRegionChange(region) {
this.setState({ region });
}
render() {
return (
/* <View><Text>hi</Text></View> />*/
<MapView style={styles.map}
region={this.state.region}
onRegionChange={this.onRegionChange}
/>
);
}
}
顯示空白頁,給我警告,' ,我嘗試了很多地圖,但我得到丟失。 那麼請幫助我如何開始?
你可以在示例代碼中找到它。 https://github.com/lelandrichardson/react-native-maps/tree/master/example –
哦,這個錯誤是有道理的......看看你如何設置區域爲空字符串?你會看到getInitialState()方法返回什麼?您可以通過調用該方法來初始化區域 –
@ cricket_007 \t 它給我警告並且什麼都不顯示,'getInitialState在app上定義。一個普通的JavaScrpit類。這僅支持使用react.creatclass創建的類。你的意思是定義一個狀態屬性嗎?' –