【发布时间】:2017-12-15 12:15:11
【问题描述】:
我想在地图中移动某个位置时更改我的初始区域,我为此使用了 onRegionChangeComplete 功能,但它一次调用两次或三次。
这是我的代码:
onRegionChangeComplete(region) {
if(!this.state.initialRegionChange){
console.log("changeRegion:"+JSON.stringify(region))
var initialRegion = {
latitude: region.latitude,
longitude :region.longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA
}
var lat = parseFloat(region.latitude)
var lang = parseFloat(region.longitude)
}else{
this.setState({
initialRegionChange:false
})
}
}
render(){
return(
<MapView
ref="map"
style={styles.map}
initialRegion={this.state.region}
provider={MapView.PROVIDER_DEFAULT}
zoomEnabled={true}
onRegionChangeComplete={this.onRegionChangeComplete.bind(this)}
pitchEnabled={true}
showsCompass={true}
showsBuildings={true}
showsUserLocation={true}
showsTraffic={true}
showsIndoors={true}
/>
)
}
请给我建议如何解决这个问题。
非常感谢任何帮助。
这是我正在关注的模块链接。 https://github.com/react-community/react-native-maps
【问题讨论】:
-
你可以通过 Logic 来处理。定义一些特定的半径或距离。所以你的 onRegionChangeComplete 不会工作两次或三次
标签: react-native react-native-android react-native-ios react-native-maps