uniapp map 地图

## 简单实现两点连线 

文档地址: uni-app官网

 

## 代码 

<template>
	<view>
		<map style="width: 100%;height: 600rpx;" :latitude="latitude" :polyline="polyline"
			:include-points="includePoints" :longitude="longitude" :markers="markers"></map>
		<image src="../../static/logo.png" mode=""></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				markers: [],
				longitude: '',
				latitude: '',
				includePoints: [],
				polyline: {}
			}
		},
		onLoad() {
			uni.getLocation({
				type: 'gcj02',
				success: (res) => {
					console.log(res, '啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊');
					const {
						longitude,
						latitude
					} = res;
					this.longitude = longitude;
					this.latitude = latitude;
					const includePoints = [{
						longitude: 120.96617296006944,
						latitude: 31.372928059895834
					}, {
						longitude: 120.98181,
						latitude: 31.38475
					}]
					const polyline = [{
						points: [{
							latitude: 31.38475,
							longitude: 120.98181
						}, {
							latitude: 31.372928059895834,
							longitude: 120.96617296006944
						}],
						width: 2,
						color: '#0000AA',
					}]
					const list = [{
						id: 12001,
						longitude: this.longitude,
						latitude: this.latitude,
						iconPath: '../../static/logo.png',
						width: 20,
						height: 20,
						alpha: 0.5,
						label: {
							content: "me",
							color: '#333',
							fontSize: 14,
							borderRadius: 20,
							textAlign: 'center',
						},
						callout: {
							content: "我的位置",
							color: '#333',
							fontSize: 14,
							borderRadius: 20,
							textAlign: 'center',
						}
					}, {
						id: 12002,
						longitude: 120.96617296006944,
						latitude: 31.372928059895834,
						iconPath: '../../static/logo.png',
						width: 20,
						height: 20,
						alpha: 0.5,
						label: {
							content: "you",
							color: '#333',
							fontSize: 14,
							borderRadius: 20,
							textAlign: 'center',
						},
						callout: {
							content: "终点",
							color: '#333',
							fontSize: 14,
							borderRadius: 20,
							textAlign: 'center',
						}
					}]
					this.$nextTick(() => {
						this.$set(this, 'markers', list)
						this.$set(this, 'includePoints', includePoints)
						this.$set(this, 'polyline', polyline)
					})
				}
			})

		},
		methods: {

		}
	}
</script>

<style>

</style>

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp中使用map组件进行标记点的操作,需要进行以下几个步骤: 1. 首先,在map标签中绑定要标记的点,可以通过在data里定义一个markers数组,并将要标记的点以对象的形式添加到该数组中。 2. 在map组件中设置markers属性为markers数组,以将数组中的点显示在地图上。 以下是一个示例代码片段,展示了如何在uniapp中使用map组件进行标记点: ``` <template> <view> <map style="width:750rpx; height:100vh;" scale="17" show-location="true" :latitude="latitude" :longitude="longitude" :markers="markers"></map> </view> </template> <script> export default { data() { return { title: 'map', longitude: '122.106863', latitude: '30.016028', markers: [ { id: 1, latitude: 30.016028, longitude: 122.106863, title: '标记点1' }, { id: 2, latitude: 30.015, longitude: 122.106, title: '标记点2' }, // 可以添加更多的标记点 ] } } } </script> ``` 在上面的示例中,markers数组中包含了两个标记点,每个标记点都有一个唯一的id、经纬度和标题。这样,在地图上就会显示这些标记点的位置。 注意:以上示例仅为演示代码,实际使用时需要根据具体需求进行调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [【记录4】uniapp Map地图组件 动态渲染markers](https://blog.csdn.net/weixin_44390036/article/details/124861312)[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_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [uniapp map地图显示图标markers问题,自定义图标不显示](https://blog.csdn.net/web13985085406/article/details/123431764)[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_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值