未定义不是 MapView.Animated 的对象(引用无效)
Undefined is not an object with MapView.Animated (refs are not working)
<MapView.Animated
ref={(mapView) => { map = mapView; }}
style={[styles.map, styleMap]}
initialRegion={{
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}}>
</MapView.Animated>
<TouchableOpacity
onPress={()=>this.map.animateCamera({
center: {
latitude: this.state.userLocation.latitude,
longitude: this.state.userLocation.longitude,
},
pitch: 45>
</TouchableOpacity>
这对我来说
Ofc 有外部视图和东西...请帮助:)
我还尝试将 ref 重命名为 map,使其成为 'var something:MapView,
它也不起作用
火车让我放弃一些代码
火车让我放弃一些代码
火车让我放弃一些代码
火车让我放弃一些代码
火车让我放弃一些代码
火车让我放弃一些代码
火车让我放弃一些代码
火车让我放弃一些代码
火车让我删除一些代码
class ChooseLocationScreen extends Component {
constructor(props) {
super(props);
this.map = React.createRef()
this.state = {
coordinate: new AnimatedRegion({
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: 0,
longitudeDelta: 0,
}),
userLocation: new AnimatedRegion({
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: 0,
longitudeDelta: 0,
}),
markerAnimation: new Animated.Value(0),
animation: new Animated.Value(0),
animationSides: new Animated.Value(1),
animationSides2: new Animated.Value(1),
mapActive: true,
isSearchScreen: false,
searchValue: '',
myGeo: false,
};
}
render() {
return (
<View style={{ flex: 1 }}>
<Animated.View style={[styles.mapContainer, animatedStyles]}>
<MapView.Animated
ref={(mapView) => { map = mapView; }}
showsUserLocation={true}
onRegionChange={() => this.onPanDrag()}
showsMyLocationButton={true}
onRegionChangeComplete={() => this.onRegionChangeComplete()}
style={[styles.map, styleMap]}
initialRegion={{
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}}
zoomEnabled={this.state.mapActive}
scrollEnabled={this.state.mapActive}
onPress={this.mapPressBackHandler}>
</MapView.Animated>
</Animated.View>
<TouchableOpacity
onPress={() => this.map.animateCamera({
center: {
latitude: this.state.userLocation.latitude,
longitude: this.state.userLocation.longitude,
},
pitch: 4
})}
style={{ position: 'absolute', top: height * 3.5 / 4, right: width / 18, zIndex: 2, alignItems: 'center' }}>
{TextNewsIcon()}
</TouchableOpacity>
</View>
)
}
}
this
中没有这样的东西。
您可以使用此代码
<MapView.Animated
ref={(mapView) => { this.map = mapView; }}
....
<TouchableOpacity
onPress={()=>this.map.animateCamera({
....
并且animateCamera
没有位置参数。
动画相机
camera: Camera, { duration: Number }
<MapView.Animated
ref={(mapView) => { map = mapView; }}
style={[styles.map, styleMap]}
initialRegion={{
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}}>
</MapView.Animated>
<TouchableOpacity
onPress={()=>this.map.animateCamera({
center: {
latitude: this.state.userLocation.latitude,
longitude: this.state.userLocation.longitude,
},
pitch: 45>
</TouchableOpacity>
这对我来说
Ofc 有外部视图和东西...请帮助:) 我还尝试将 ref 重命名为 map,使其成为 'var something:MapView, 它也不起作用
火车让我放弃一些代码 火车让我放弃一些代码 火车让我放弃一些代码 火车让我放弃一些代码 火车让我放弃一些代码 火车让我放弃一些代码 火车让我放弃一些代码 火车让我放弃一些代码 火车让我删除一些代码
class ChooseLocationScreen extends Component {
constructor(props) {
super(props);
this.map = React.createRef()
this.state = {
coordinate: new AnimatedRegion({
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: 0,
longitudeDelta: 0,
}),
userLocation: new AnimatedRegion({
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: 0,
longitudeDelta: 0,
}),
markerAnimation: new Animated.Value(0),
animation: new Animated.Value(0),
animationSides: new Animated.Value(1),
animationSides2: new Animated.Value(1),
mapActive: true,
isSearchScreen: false,
searchValue: '',
myGeo: false,
};
}
render() {
return (
<View style={{ flex: 1 }}>
<Animated.View style={[styles.mapContainer, animatedStyles]}>
<MapView.Animated
ref={(mapView) => { map = mapView; }}
showsUserLocation={true}
onRegionChange={() => this.onPanDrag()}
showsMyLocationButton={true}
onRegionChangeComplete={() => this.onRegionChangeComplete()}
style={[styles.map, styleMap]}
initialRegion={{
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}}
zoomEnabled={this.state.mapActive}
scrollEnabled={this.state.mapActive}
onPress={this.mapPressBackHandler}>
</MapView.Animated>
</Animated.View>
<TouchableOpacity
onPress={() => this.map.animateCamera({
center: {
latitude: this.state.userLocation.latitude,
longitude: this.state.userLocation.longitude,
},
pitch: 4
})}
style={{ position: 'absolute', top: height * 3.5 / 4, right: width / 18, zIndex: 2, alignItems: 'center' }}>
{TextNewsIcon()}
</TouchableOpacity>
</View>
)
}
}
this
中没有这样的东西。
您可以使用此代码
<MapView.Animated
ref={(mapView) => { this.map = mapView; }}
....
<TouchableOpacity
onPress={()=>this.map.animateCamera({
....
并且animateCamera
没有位置参数。
动画相机
camera: Camera, { duration: Number }