feat(地图导航): 添加网点地图导航功能

在多个页面中添加了地图导航功能,用户可以通过点击地址或导航图标打开地图并查看具体位置。如果位置信息缺失,会提示用户“暂无位置信息”。此功能提升了用户体验,方便用户快速找到网点位置。
This commit is contained in:
XiaoMo 2025-04-10 22:36:01 +08:00
parent 1af84dc1ee
commit 47d847e138
4 changed files with 37 additions and 5 deletions

View File

@ -98,6 +98,20 @@ Page({
}, },
load: function (e) { load: function (e) {
console.log(e); console.log(e);
},
openLocation: function(e) {
var latitude = Number(e.currentTarget.dataset.latitude);
var longitude = Number(e.currentTarget.dataset.longitude);
var name = e.currentTarget.dataset.name;
var address = e.currentTarget.dataset.address;
wx.openLocation({
latitude: latitude,
longitude: longitude,
name: name,
address: address,
scale: 18
});
var t = e.currentTarget.dataset.index, a = this.data.swiperWidth * e.detail.height / e.detail.width; var t = e.currentTarget.dataset.index, a = this.data.swiperWidth * e.detail.height / e.detail.width;
this.data.banner[t].height = a, this.setData({ this.data.banner[t].height = a, this.setData({
swiperHeight: a swiperHeight: a

View File

@ -141,4 +141,22 @@ Page({
} }
}) })
}, },
// 打开地图导航
openLocation() {
if (this.data.info.latitude && this.data.info.longitude) {
wx.openLocation({
latitude: Number(this.data.info.latitude),
longitude: Number(this.data.info.longitude),
name: this.data.info.name,
address: this.data.info.address,
scale: 18
})
} else {
wx.showToast({
title: '暂无位置信息',
icon: 'none'
})
}
},
}) })

View File

@ -8,9 +8,9 @@
<view class="ld" wx:for="{{info.service}}" wx:key="index_i" wx:for-item="s" style="background-color: {{s.color}};">{{s.label}}</view> <view class="ld" wx:for="{{info.service}}" wx:key="index_i" wx:for-item="s" style="background-color: {{s.color}};">{{s.label}}</view>
</view> </view>
<view class="tag">{{info.tags}}</view> <view class="tag">{{info.tags}}</view>
<view class="ads"><text class="iconfont icon-dingwei"></text>{{info.address}}</view> <view class="ads" bindtap="openLocation"><text class="iconfont icon-dingwei"></text>{{info.address}}</view>
<view class="ads yingye"><text class="iconfont icon-shijian"></text>{{info.businesshours || "24小时"}}</view> <view class="ads yingye"><text class="iconfont icon-shijian"></text>{{info.businesshours || "24小时"}}</view>
<view class="dw"> <view class="dw" bindtap="openLocation">
<text class="ico iconfont icon-daohangdaohang"></text> <text class="ico iconfont icon-daohangdaohang"></text>
<view class="jl">{{info.distance}}</view> <view class="jl">{{info.distance}}</view>
</view> </view>

View File

@ -4,8 +4,8 @@
<view bindtap="toPage" class="more" data-refresh="1" data-url="map/map">全部网点></view> <view bindtap="toPage" class="more" data-refresh="1" data-url="map/map">全部网点></view>
<view class="title_c">离我最近<view class="line"></view></view> <view class="title_c">离我最近<view class="line"></view></view>
</view> </view>
<view bindtap="toPage" class="index-wangdian-box" wx:for="{{wangdianList}}" wx:key="index" wx:for-item="item" data-refresh="1" data-url="wangdian/wangdian?number={{item.number}}"> <view class="index-wangdian-box" wx:for="{{wangdianList}}" wx:key="index" wx:for-item="item">
<view class="info"> <view class="info" bindtap="toPage" data-refresh="1" data-url="wangdian/wangdian?number={{item.number}}">
<view class="title"> <view class="title">
<view class="title_c">{{item.name}}</view> <view class="title_c">{{item.name}}</view>
<view class="ld" wx:for="{{item.service}}" wx:key="index_i" wx:for-item="s" style="background-color: {{s.color}};">{{s.label}}</view> <view class="ld" wx:for="{{item.service}}" wx:key="index_i" wx:for-item="s" style="background-color: {{s.color}};">{{s.label}}</view>
@ -14,7 +14,7 @@
<view class="ads"><text class="iconfont icon-dingwei"></text>{{item.address}}</view> <view class="ads"><text class="iconfont icon-dingwei"></text>{{item.address}}</view>
<view class="jiqi">洗车机:闲{{item.free}}/{{item.machine}}台</view> <view class="jiqi">洗车机:闲{{item.free}}/{{item.machine}}台</view>
<view class="yingye">{{item.businesshours || '24小时'}}</view> <view class="yingye">{{item.businesshours || '24小时'}}</view>
<view class="dw"> <view class="dw" catchtap="openLocation" data-latitude="{{item.latitude}}" data-longitude="{{item.longitude}}" data-name="{{item.name}}" data-address="{{item.address}}">
<text class="ico iconfont icon-daohangdaohang"></text> <text class="ico iconfont icon-daohangdaohang"></text>
<view class="jl">{{item.distance}}</view> <view class="jl">{{item.distance}}</view>
</view> </view>