微信小程序地图导航功能实现完整源代码附效果图(推荐)
程序员文章站
2023-12-15 13:10:22
正文:
一:需求及效果图展示
从后端api获取到起始地和目的地的经纬度坐标与地名。用户点击起始地便打开地图展示坐标的附近街景,路线,或者打开外部地图。
二:源代码...
正文:
一:需求及效果图展示
从后端api获取到起始地和目的地的经纬度坐标与地名。用户点击起始地便打开地图展示坐标的附近街景,路线,或者打开外部地图。
二:源代码
<block wx:for="{{data_2}}" wx:key='index' wx:if="{{data_2.length}}"> <view style='margin-left:10rpx;'>订单号: {{item.order_num}}</view> <view class='page_row'> <view class='centent'> <view style='margin-left:10rpx;' wx:if='{{item.server_info.linkman}}'>下单人: {{item.server_info.linkman}} <text style='color:#999;margin-left:40rpx;font-size:32rpx;' wx:if='{{item.server_info.tel}}'>联系电话: {{item.server_info.tel}}</text> </view> <view style='color:#999;margin-top:15rpx;' wx:if='{{item.car_info.title}}'> <view style='color:#999;margin-left:10rpx;font-size:28rpx' bindtap='apen_add'data-name='{{item.server_info.address}}' data-latitude_siji='{{item.server_info.coordinate_start}}'><image style='width:32rpx;height:32rpx' src='../../image/location.png'/> 导航至起始地:{{item.server_info.address}} </view> </view> <view style='color:#999;margin-top:15rpx;' wx:if='{{item.car_info.title}}'> <view style='color:#999;margin-left:10rpx;font-size:28rpx' bindtap='apen_add' data-name='{{item.server_info.address_end_text}}' data-longitude_siji='{{item.server_info.coordinate_end}}'><image style='width:32rpx;height:32rpx' src='/image/location.png'/> 导航至目的地: {{item.server_info.address_end_text}} </view> </view> <view style='color:#999;margin-top:15rpx;' wx:if='{{item.car_info.title}}'> <view style='color:#999;margin-left:10rpx;font-size:28rpx'> 分配时间:{{item.time_tired}}</view> </view> </view> </view> <view class='xxx'></view> </block>
apen_add: function (e) { var that = this var latitude, longitude var name = e.currenttarget.dataset.name if (e.currenttarget.dataset.latitude_siji) { var latitude_siji = e.currenttarget.dataset.latitude_siji.split(',') latitude = number(latitude_siji[0]) longitude = number(latitude_siji[1]) } if (e.currenttarget.dataset.longitude_siji) { var longitude_siji = e.currenttarget.dataset.longitude_siji.split(',') latitude = number(longitude_siji[0]) longitude = number(longitude_siji[1]) } wx.getsetting({ success: (res) => { if (res.authsetting['scope.userlocation'] != undefined && res.authsetting['scope.userlocation'] != true) { wx.showmodal({ title: '是否授权当前位置', content: '需要获取您的地理位置,请确认授权,否则地图定位功能将无法使用', success: function (res) { if (res.cancel) { console.info("1授权失败返回数据"); } else if (res.confirm) { //village_lbs(that); wx.opensetting({ success: function (data) { if (data.authsetting["scope.userlocation"] == true) { wx.showtoast({ title: '授权成功', icon: 'success', duration: 5000 }) wx.openlocation({ latitude: latitude, longitude: longitude, name: name, scale: 28 }) } else { wx.showtoast({ title: '授权失败', icon: 'success', duration: 5000 }) } } }) } } }) } else { wx.openlocation({ latitude: latitude, longitude: longitude, name: name, scale: 28 }) } } }) },
数据请求
show_data: function () { var that = this; if (wx.getstoragesync('register') != '司机') { var data = { openid: app._openid, program_id: app.jtappid, only_num: app._openid, online_code: wx.getstoragesync('online_code') } var url = '/pg.php/cartrailer/roder_list'; util.request(url, 'get', data, '正在加载', function (res) { res.data.reverse() for (var i = 0; i < res.data.length; i++) { res.data[i].time_xd = util.js_date_time(res.data[i].time_xd) switch (res.data[i].state) { case '1': that.setdata({ data_1: that.data.data_1.concat(res.data[i]), }) break; case '2': that.setdata({ data_2: that.data.data_2.concat(res.data[i]), }) break; case '3': that.setdata({ data_3: that.data.data_3.concat(res.data[i]), }) break; case '4': that.setdata({ data_4: that.data.data_4.concat(res.data[i]), }) break; } } }) } else { var data = { openid: app._openid, program_id: app.jtappid, online_code: wx.getstoragesync('online_code') } var url = '/pg.php/cartrailer/driver_order_list'; util.request(url, 'get', data, '正在加载', function (res) { for (var i = 0; i < res.data.length; i++) { res.data[i].time_tired = util.js_date_time(res.data[i].time_tired) } res.data.reverse() that.setdata({ siji: true }) for (var i = 0; i < res.data.length; i++) { switch (res.data[i].state) { case '1': that.setdata({ data_1: that.data.data_1.concat(res.data[i]), }) break; case '2': that.setdata({ data_2: that.data.data_2.concat(res.data[i]), }) break; case '3': that.setdata({ data_3: that.data.data_3.concat(res.data[i]), }) break; case '4': that.setdata({ data_4: that.data.data_4.concat(res.data[i]), }) break; } } }) } },
以上所述是小编给大家介绍的微信小程序地图导航功能实现详解整合,希望对大家有所帮助