uni-app 微信小程序地图增加标记点,并实现点击弹窗

项目需求,在微信小程序的地图中,实现打点,然后点击某个点要能弹出关于这个点的某些信息,同时在当前点跳到其他点时,对应信息也要替换,点击空白处要关闭弹窗,在此做个记录最终实现效果如图**(展示用的是小程序模拟器,有点小问题,正常点击点时会把这个点设置为中心点,而不是像GIF一样,一直往定位点跳)**...
摘要由CSDN通过智能技术生成

项目需求,在微信小程序的地图中,实现打点,然后点击某个点要能弹出关于这个点的某些信息,同时在当前点跳到其他点时,对应信息也要替换,点击空白处要关闭弹窗,在此做个记录

最终实现效果如图 (展示用的是小程序模拟器,有点小问题,真机调试是正常的,点击某个点时会把这个点设置为中心点,而不是像GIF一样,一直往定位点跳)

在这里插入图片描述
废话不多说,直接上代码

<template>
	<view>
		<map 
			id="map" 
			style="width: 100%; height: 100vh;" 
			:show-location="true"
			:latitude="map.latitude" 
			:longitude="map.longitude" 
			:scale="map.scale" 
			:markers="map.markers" 
			:circles="map.circles" 
			@markertap="markertap"
			@tap="tap"
		>
			<cover-image class="location" src="/static/img/map/location.png" @click="getLocation"></cover-image>
			<cover-image class="record" src="/static/img/map/record.png" @click="shouSleet"></cover-image>
			<cover-image class="refresh" src="/static/img/map/refresh.png" @click="loadData"></cover-image>
			
			<lv-select
				showValue="name"
				uniShadow="true"
				@handleSearch="searchHandle"
				@change="searchChange"
				:infoList="select.infoList"
				v-model="select.searchValue"
				:loading="select.loading"
				:isShowSelect="isShowSelect"
				>
			</lv-select>
			
			<view v-if="viewshow" class="uni-row-show">
				<view class="uni-flex uni-row">
					<text>标题:</text>
					<view style="-webkit-flex: 1;flex: 1;">
						<text style="color: gray;">{
   {
   map.marker.customData.localAccentTitle}}</text>
					</view>
					<cover-image class="close" src="/static/img/map/cha.png" @click="closeshow"></cover-image>
				</view>
				<view class="uni-flex uni-row" style="-webkit-flex: 1;flex: 1;">
					<text>描述:</text>
					<text>{
   {
   map.marker.customData.localAccentDescribe}}</text>
				</view>
				<view class="uni-flex uni-row" style="-webkit-flex: 1;flex: 1;">
					<text>时间:</text>
					<text>{
   {
   map.marker.customData.createTime}}</text>
				</view>
				<view class="uni-flex uni-row" style="-webkit-flex: 1;flex: 1;">
					<text>作者:</text>
					<text>{
   {
   map.marker.customData.createPeople}}</text>
				</view>
				
				<view class="audio" v-if="audioShow">
					<imt-audio :src="map.marker.customData.path"></imt-audio>
				</view>
			</view>
		</map>
	</view>
</template>

<script>
	import lvSelect from 'components/lv-select/lv-select'	//搜索组件
	import imtAudio from 'components/imt-audio/imt-audio';	//音频播放组件
	import {
    mapState, mapMutations } from 'vuex'
	
	export default {
   
		components: {
   imtAudio, lvSelect},
	    data() {
   
			return {
   
				viewshow: false,
				audioShow: false,
				isShowSelect: 
  • 10
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 16
    评论
uni-app是一款基于Vue.js框架的跨平台开发工具,可以同时开发微信小程序、H5、App等多个平台的应用。在uni-app中,我们可以很方便地使用地图组件来标记。 首先,我们需要引入uni-app官方提供的地图组件,在页面的json文件中添加以下代码: ``` { "usingComponents": { "uni-map": "@dcloudio/uni-map/uni-map" } } ``` 然后,在需要使用地图的页面中,在template中添加以下代码: ``` <template> <view> <uni-map :longitude="longitude" :latitude="latitude" :markers="markers" :include-points="true" ></uni-map> </view> </template> ``` 在script中,我们需要定义地图的经纬度和标记的数据: ``` <script> export default { data() { return { longitude: 113.324520, latitude: 23.099994, markers: [{ id: 1, longitude: 113.324520, latitude: 23.099994, title: '标记1', iconPath: '/static/marker.png', width: 30, height: 30 }, { id: 2, longitude: 113.326520, latitude: 23.099994, title: '标记2', iconPath: '/static/marker.png', width: 30, height: 30 }] } } } </script> ``` 我们可以通过设置longitude和latitude来指定地图的中心,通过markers来设置标记的位置、标题、图标等信息。iconPath需要提前准备好对应的图标文件。 最后,在地图组件上设置:include-points="true",可以使得地图自动包含所有标记,确保能够显示所有标记。 以上就是使用uni-app来在微信小程序标记的方法。通过引入uni-app提供的地图组件,结合相关的属性和数据即可实现地图标记功能。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值