【uniapp】实现电子围栏:


一、效果:

在这里插入图片描述

二、文档:

注意:地图服务商说明

在这里插入图片描述

三、案例:

在这里插入图片描述

OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77

<map id="map" style="height: 100%; width: 100%;"  :latitude="latitude" :longitude="longitude" :markers="covers" :polyline="polylineD" :polygons="polygons"></map>
export default {
	data() {
		return {
			polygons: [], 
			...
		}
	},
	methods: {
		/*
		* @Author: SunPeng
		* @Date: 2022-12-20 14:45:41
		* @Description: 获取电子围栏数据
		*/
		getGeofenceData() {
			const that = this
			let param = {
				deptId: uni.getStorageSync('userSiteInfo').deviceTypeId, // stringtrue机构ID
				stationId: uni.getStorageSync('userSiteInfo').selectId, //	string	true	磅点ID
				pageNum: '1', //string false 当前页数
				pageSize: '100', //string false 每页条数
			}

			this.questFun('geofence/search', 'get', 'bd', param, function(res) {
					if (res.data.code == 0) {
						that.polygons = []
						if (res.data.data.list.length == 0) {
							uni.showToast({
								title: '没有围栏数据',
								icon: 'none'
							})
							return
						}
						res.data.data.list.forEach(items => {
							let _data = [];
							items.points.forEach(item => {
								// console.log(item)   注意经纬度不要搞错了
								_data.push({ latitude: item[1], longitude: item[0], })
							});
							let ps = {
								points: _data,
								strokeColor: "#FD302F",
								strokeWidth: 2,
								fillColor: "green",
								fillOpacity: 0.4,
							};
							that.polygons.push(ps);
							// console.log(that.polygons)
						})
					} else {
						that.polygons = []
						uni.showToast({
							title: 'res.data.msg',
							icon: 'none'
						})
					}
				})
			},
	}
}
四、获取的数据详情:

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sun Peng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值