reactjs - React-native-maps 限制平移区域

标签 reactjs google-maps react-native react-native-maps

有没有办法将 map 限制在特定区域,以便平移和缩放包含在该区域内,而外面的所有内容都被锁定?我想限制用户可以在 map 上看到的区域。
我正在通过 react-native-maps https://github.com/react-community/react-native-maps 使用谷歌 map

这是我的代码,目前对可以缩放多远或可以向任一侧平移多少没有限制

    <View style={styles.container}>
        <MapView style={styles.map}
          provider= { PROVIDER_GOOGLE }
          customMapStyle={mapStyle}
          initialRegion={{
            latitude: 59.2937025,
            longitude: 18.0813377,
            latitudeDelta: 0.012,
            longitudeDelta: 0.012,

          }}
        />
    </View> 

最佳答案

TyBourque 提交的解决方案奏效了。
更复杂的 anwser,您可以使用 maxZoomLevel Prop 来限制缩放。然后您将需要使用 onPanDrag 事件并需要检查 {坐标:LatLng,位置:点} 是否在边界内,如果不在边界内,则将其重置为之前的有效位置。

关于reactjs - React-native-maps 限制平移区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49923304/

相关文章:

reactjs - 带有 fetch api 的 React hook

css - 具有奇怪边缘的 SVG 图标渲染

android - React Native 应用程序中的 Redux 用例

react-native - 如何让 fontSize 响应原生 android 选择器?

ios - 检测 App React App 是否在模拟器中运行

reactjs - 根据当前 URL 更改 Link 的 className,React

javascript - react .js : Why delete button is not working?

android - Google Place Picker 获取城市?

android - 谷歌地图上的当前位置没有打开 GPS(android 设备)?

android - 谷歌地图安卓 v2