首页 > 解决方案 > 自动缩放到当前位置不适用于特定区域

问题描述

我正在使用 react-native-maps,我一直在显示当前位置的地图,缩放级别在某些位置看起来不错,而对于某些位置,地图看起来很模糊。我尝试在此链接之后计算latitudeDeltalongitudeDelta值,但没有运气。如何在城市级别缩放地图?

这是我的代码

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>


模糊的地图图像

标签: react-nativereact-native-maps

解决方案


尝试使用我帮助你的 animateToRegion() 方法。

this.mapView.animateToRegion(initialRegion, 2000); // pass your region object as first parameter

推荐阅读