中国地图经纬度范围,用多个矩形表示大致范围

经纬度区域

// 每行代表一个矩形范围,第一个点是左下角,第二个点是右上角

(124.37, 39.75), (135.25, 53.65)
(115.24, 46.95), (124.37, 53.65)
(110.68, 43.01), (124.37, 46.95)
(79.7, 43.01), (97.07, 49.24)
(73.37, 26.61), (95.45, 43.01)
(95.45, 27.73), (124.37, 43.01)
(97.50, 21.13), (124.37, 27.73)
(107.37, 3.18), (122.04, 21.13)

在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要锁定小程序地图经纬度范围,可以使用地图 API 中的地图限制功能。通过设置地图的边界,可以限制用户在地图上浏览的区域。具体步骤如下: 1. 在小程序中引入地图组件,如使用腾讯地图:`<map id="map" latitude="{{latitude}}" longitude="{{longitude}}" />` 2. 在小程序页面的 JS 文件中,设置地图组件的属性,包括地图中心点的经纬度、缩放级别和地图边界范围等。 ```javascript Page({ data: { latitude: 39.90469, longitude: 116.40717, scale: 16, markers: [], covers: [], // 设置地图边界范围 includePoints: [{ latitude: 39.870801, longitude: 116.372276, }, { latitude: 39.935426, longitude: 116.449216, }], }, }) ``` 3. 在地图组件上绑定事件,如 `regionchange` 事件,以监听用户在地图上的操作。 ```javascript <map id="map" latitude="{{latitude}}" longitude="{{longitude}}" scale="{{scale}}" include-points="{{includePoints}}" bindregionchange="regionChange" /> ``` 4. 在事件处理函数中,判断用户的操作是否超出了地图边界,如果超出,则将地图中心点和缩放级别还原到边界内。 ```javascript Page({ data: { latitude: 39.90469, longitude: 116.40717, scale: 16, markers: [], covers: [], includePoints: [{ latitude: 39.870801, longitude: 116.372276, }, { latitude: 39.935426, longitude: 116.449216, }], }, regionChange(e) { if (e.type === 'end') { this.mapCtx = wx.createMapContext('map') this.mapCtx.getCenterLocation({ success: (res) => { const latitude = res.latitude const longitude = res.longitude if (!this.checkInBounds(latitude, longitude)) { // 用户操作超出地图边界,还原到边界内 this.mapCtx.moveToLocation({ latitude: this.data.latitude, longitude: this.data.longitude, }) this.mapCtx.setZoom({ scale: this.data.scale, }) } } }) } }, checkInBounds(latitude, longitude) { const bounds = this.data.includePoints const minLat = Math.min(bounds[0].latitude, bounds[1].latitude) const maxLat = Math.max(bounds[0].latitude, bounds[1].latitude) const minLng = Math.min(bounds[0].longitude, bounds[1].longitude) const maxLng = Math.max(bounds[0].longitude, bounds[1].longitude) return (latitude >= minLat && latitude <= maxLat && longitude >= minLng && longitude <= maxLng) }, }) ``` 通过以上步骤,就可以实现锁定小程序地图经纬度范围的功能。用户在地图上的操作会被限制在指定的范围内,确保用户无法浏览到不允许访问的区域

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值