小程序之地图标注以及导航

简单说一下遇到的问题,标注点出不来情况,之后是.wxml文件中map标签行内定义longitude="{{map.lng}}" 、latitude="{{map.lat}}"、markers="{{map.markers}}"然后在.js文件中也分别定义。

.wxml文件

<view class='wc_area_mapbox'>
     <map class='wc_area_map' bindtap='location' bindmarkertap='location' show-location longitude="{{map.lng}}" latitude="{{map.lat}}" markers="{{map.markers}}"></map>
</view>

.js文件

const app = getApp();
Page({
    data: {
        map:{
            lat:0,         //这里必须定义lat,lng,不然标注点出不来
            lng:0,
            markers:[],
            navigation:null
        },
        service_detail: [],
        wc_id:null,
        
    },

    onLoad: function (options) {
        var that = this;
        that.setData({
            wc_id: options.id
        })
        that.get_wc_detail();
    },
    get_wc_detail: function () {
        var that=this;
        wx.showLoading({
            title: '加载中',
        })
        wx.request({
            url: app.globalData.url + 'index.php/api/Home/service_detail',
            data:{
                id: that.data.wc_id,
                lng: app.globalData.location.longitude,
                lat: app.globalData.location.latitude
            },
            success:function(res){
                console.log(res)
                wx.hideLoading();
                if(res.data.status==200){
                    that.setData({
                        navigation: res.data.data.name,
                        service_detail: res.data.data,
                        'map.lat': res.data.data.lat,
                        'map.lng':res.data.data.lng,
                        'map.markers':[{
                            latitude: res.data.data.lat,     //这里也定义
                            longitude: res.data.data.lng,
                            name: res.data.data.title
                        }]
                    })
                    wx.setNavigationBarTitle({
                        title: that.data.navigation
                    })  
                }else{
                    wx.showToast({
                        title: res.data.error,
                        icon:'loading',
                        duration:1000
                    })
                }
            },
            fail:function(){
                wx.hideLoading();
                wx.showToast({
                    title: '请求失败',
                    icon:'loading',
                    duration:1000
                })
            }
        })
    },
    location:function(){
        wx.openLocation({                    //调用导航
            latitude: this.data.map.lat,
            longitude: this.data.map.lng,
            name: this.data.navigation,
            scale: 28
        })
    }
})

 

转载于:https://www.cnblogs.com/wanan-01/p/9078059.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值