react-native - 自动缩放到当前位置不适用于特定区域
问题描述
我正在使用 react-native-maps,我一直在显示当前位置的地图,缩放级别在某些位置看起来不错,而对于某些位置,地图看起来很模糊。我尝试在此链接之后计算latitudeDelta
和longitudeDelta
值,但没有运气。如何在城市级别缩放地图?
这是我的代码
let region = {
latitude: this.props.latitude,
longitude: this.props.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
};
<MapView
style={[styles.map, {flex: 3, height: deviceHeight / 50, width: deviceWidth}]}
region={this.state.mapRegion}
showsUserLocation={true}
followUserLocation={true}
initialRegion={this.state.initialRegion}
onRegionChangeComplete={mapRegion => {
this.updateAddress(mapRegion);
}}>
<MapView.Marker
coordinate={{
latitude: this.state.mapRegion ? this.state.mapRegion.latitude : this.state.latitude,
longitude: this.state.mapRegion ? this.state.mapRegion.longitude : this.state.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}>
</MapView.Marker>
</MapView>
解决方案
尝试使用我帮助你的 animateToRegion() 方法。
this.mapView.animateToRegion(initialRegion, 2000); // pass your region object as first parameter
推荐阅读
- python - Streamlit 中的登录页面问题
- java - 从键盘读取并忽略打印的文本
- javascript - 如何使用 Javascript 监听值变化的特定键?
- javascript - 通过计算字符长度将 JS 数组拆分和连接成块
- javascript - 广告未呈现
- json - Jq 在使用 AWS Secrets Manager 解析时添加额外的双引号
- c# - ServiceStack.Redis:所有 MQ 请求处理程序的一个线程池?
- python - 列表理解以删除不需要的对象。验证它按预期工作
- php - 从肥皂响应中提取价值
- ios - 在 contentSize 超过 visibleSize 之前,垂直 UIScrollView 不可交互