<MapView
style={ styles.map }
initialRegion={{
latitude: this.state.lat,
longitude:this.state.long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
region={{latitude: this.state.lat,
longitude:this.state.long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421}}
ref={(ref) => { this.mapRef = ref }}
>
<Polyline
coordinates={[
{ latitude: this.state.picklat, longitude: this.state.picklong },
{ latitude: this.state.droplat, longitude: this.state.droplong }
]}
strokeColor="#000" // fallback for when `strokeColors` is not supported by the map-provider
strokeColors={[
'#7F0000',
'#00000000', // no color, creates a "long" gradient between the previous and next coordinate
'#B24112',
'#E5845C',
'#238C23',
'#7F0000'
]}
strokeWidth={6}
/>
<Marker draggable
coordinate={{latitude: this.state.picklat,
longitude: this.state.picklong}}
pinColor={"#56954A"}
onDragEnd={(e)=>{this.setState({picklat:e.nativeEvent.coordinate.latitude,picklong:e.nativeEvent.coordinate.longitude},
this.mapRef.fitToCoordinates([
{ latitude: this.state.picklat, longitude: this.state.picklong },
{ latitude: this.state.droplat, longitude: this.state.droplong }
], { edgePadding: { top: 10, right: 10, bottom: 10, left: 10 }, animated: true }))}}
/>
<Marker draggable
coordinate={{latitude: this.state.droplat,
longitude: this.state.droplong}}
pinColor={"#C5441B"}
onDragEnd={(e)=>this.setState({droplat:e.nativeEvent.coordinate.latitude,droplong:e.nativeEvent.coordinate.longitude,lat:e.nativeEvent.coordinate.latitude,long:e.nativeEvent.coordinate.longitude})
}
/>
当执行on dragEnd函数时,相机/视图中没有变化,看来fittocoordinates在代码中没有任何作用,但是我需要一些人来帮助解决这一问题,因为我一直在为此工作自从我是编程新手以来的15天