gpt4 book ai didi

react-native - 如何在react-native-map中放大/缩小?

转载 作者:行者123 更新时间:2023-12-03 13:06:29 24 4
gpt4 key购买 nike

我正在使用react-native来构建 map 应用程序。我正在使用的api来自以下链接:https://github.com/lelandrichardson/react-native-maps。以下是我将 map 带到应用程序中的代码。我徘徊在该 map 上如何给出缩放值。以及当用户单击 map 上的按钮时如何更改缩放值。我应该使用什么缩放API来实现此目的?

import React, {


AppRegistry,
Component,
StyleSheet,
Text,
View,
Image,
ListView,
TextInput,
TouchableHighlight,
Dimensions,
//MapView,
} from 'react-native';

import MapView from 'react-native-maps';

const styles = StyleSheet.create({
map: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
},
container: {
flexDirection: 'row',
justifyContent: 'space-between',
padding: 30,
flex: 1,
alignItems: 'center'
},
inputText: {
height: 36,
padding: 4,
marginRight: 5,
flex: 4,
fontSize: 18,
borderWidth: 1,
borderColor: '#48BBEC',
borderRadius: 8,
color: '#48BBEC'
}
});

class MapPage extends Component{

constructor(props){
super(props);
this.state = {
region:{
latitude: 4.21048,
longitude: 101.97577,
latitudeDelta: 10,
longitudeDelta: 5
}
}
}

render() {
return(
<View style={styles.container}>
<TextInput style={styles.inputText}></TextInput>
<MapView
style={ styles.map }
mapType={"standard"}
region={this.state.region}
zoomEnabled={true}
scrollEnabled={true}
showsScale={true}
></MapView>
</View>
)
}
}

module.exports = MapPage;

最佳答案

您应该使用animateToRegion方法(请参阅here)

它采用具有latitudeDeltalongitudeDelta的区域对象。使用这些设置缩放级别。

更新:

Region对象中,latitudelongitude指定中心位置,而latitudeDeltalongitudeDelta指定可见 map 区域的跨度。

这张来自this博客文章的图片很好地说明了这一点(LatΔ和LngΔ)。
enter image description here

关于react-native - 如何在react-native-map中放大/缩小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36685372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com