uniapp 地图组件 地图展示后台商家列表数据

《uniapp 地图组件 地图展示后台商家列表数据》 官方组件  只做笔记,以后使用

 

<template>
	<view class="content">
		<map id="map" class="map" :show-location="true" :latitude="latitude" :longitude="longitude"></map>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				latitude: 22.820291,
				longitude: 108.370653,
				positions: [],
			}
		},
		onLoad() {
			// this.getStore();
		},
		onReady() {
			this._mapContext = uni.createMapContext("map", this);

			// 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
			this._mapContext.initMarkerCluster({
				enableDefaultStyle: false,
				zoomOnClick: true,
				gridSize: 60,
				complete(res) {
					console.log('initMarkerCluster', res)
				}
			});

			this._mapContext.on("markerClusterCreate", (e) => {
				console.log("markerClusterCreate", e);
			});

			this.addMarkers();
		},
		methods: {
			//获取商家列表
			getStore() {
				let that = this
				that.$api.request(that.route.club.store, {}, 'GET').then(res => {
					console.log(res, '商家列表');
					that.positions = res.data;
				});
			},
			addMarkers() {
				let that = this
				const marker = {
					id: 1,
					iconPath: '',
					width: 50,
					height: 50,
					joinCluster: true, // 指定了该参数才会参与聚合
					label: {
						width: 50,
						height: 30,
						borderWidth: 1,
						borderRadius: 10,
						bgColor: '#ffffff',
						content:''
					}
				};
				//请求后台列表数据
				that.$api.request(that.route.club.store, {}, 'GET').then(res => {
					console.log(res, '商家列表');
					that.positions = res.data;
					const markers = []
					console.log(that.positions, 'that.positions')
					that.positions.forEach((p, i) => {
						console.log(p, i, 'positions');
						const newMarker = Object.assign({}, marker, p)
						newMarker.id = p.id;
						newMarker.iconPath = p.thumb;
				     	newMarker.label.content = p.name;
						console.log(p.name, 'p.name');
						markers.push(newMarker)
					})
					that._mapContext.addMarkers({
				    markers,
				 	clear: false,
						complete(res) {
							console.log('addMarkers', res)
						}
					})
				});


			}
		}
	}
</script>

<style>
	.content {
		flex: 1;
	}

	.map {
		flex: 1;
		width: 100%;
		height: 90vh;
	}
</style>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp地图组件是一个用于展示地图组件,它是使用vue.js开发的一个前端框架。开发者可以使用一套代码编写应用,并发布到多个平台,包括iOS、Android、Web以及各种小程序和快应用平台。 地图组件使用腾讯地图展示地图,并且可以通过定位API(uni.getLocation)获取坐标信息。在uniapp使用地图组件时,需要注意经纬度必填,如果不填,则默认值是北京的经纬度。 使用uniapp地图组件的基本使用方法是将map组件添加到页面,并设置相应的属性。通过设置属性,可以实现地图的缩放、心点位置、标记点等功能。具体的属性设置可以参考uniapp的官方文档。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [uniapp的map地图组件介绍](https://blog.csdn.net/weixin_67490903/article/details/126013460)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [uniappmap组件的详细总结,含文字气泡、点击定位等(附全部源码)](https://blog.csdn.net/weixin_56740218/article/details/125612958)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值