2017-09-22 35 views
0

我正在使用ReactNative和GoogleMaps API(通過Airbnb)。我實施了GoogleMaps地理定位搜索,並且收到經緯度爲經緯度的響應。ReactNative視口隨GoogleMaps地理位置搜索變化

現在我無法重新渲染地圖以顯示搜索緯度/長度。

迄今爲止解決這個問題我曾嘗試:

  • 更改的MapView
  • 的區域屬性更改的MapView
  • 的onChange和地區的不同組合的initialRegion屬性狀態的狀態,沒有一個工作。

希望聽到下一步嘗試的建議 - 你可以找到我的完整代碼here

回答

1

你可以改變你的代碼是這樣

render() { 
return (
    <View style={styles.container}> // add a container view with absolute position same as map 
    <MapView 
    provider={ PROVIDER_GOOGLE } 
    style={styles.container} 
    region={this.state.locationCoordinates} // change from initialRegion to region 
    zoomEnabled={true} 
    scrollEnabled={true} 
    > 
     <MapView.Marker 
     coordinate={{ 
     latitude: 37.7749, 
     longitude: -122.4194, 
     }} 
    /> 
    </MapView> 
    <View style={styles.inputContainer}> // remove input container from inside the MapView 
     <TextInput 
     placeholder="Where to?" 
     style={ styles.input } 
     onChangeText={this.handleLocationInput} 
     value={this.state.locationInput} 
     onSubmitEditing={this.handleSubmit.bind(this)} 
     /> 
    </View> 
    </View> 
); 
} 
+0

當我改變initialRegion,我能跳轉到新的搜索位置 - 但我失去了在地圖上滾動(儘管我的能力有一個scrollEnabled道具設置爲true)。你知道如何解決這個問題嗎? – gfahs

+0

發生了什麼劑量它根本不移動或什麼也應該使用區域不初始區域 –

+0

請注意,您的代碼有initialRegion和答案只是區域 –