小程序map学习:使用map获取当前位置并显示出来

您所在的位置:网站首页 微信小程序一直获取不到定位 小程序map学习:使用map获取当前位置并显示出来

小程序map学习:使用map获取当前位置并显示出来

2024-03-02 14:49| 来源: 网络整理| 查看: 265

在小程序开发的过程中,我碰到过一个做map的需求,在我开发的时候我碰到了一些问题,这里总结出来,给大家一些解决方法。

简易小程序dome下载

代码片段分享:

js部分:

var amapFile = require('../../libs/amap-wx.js');//如:..­/..­/libs/amap-wx.js Page({ data: { markers: [], latitude: '', longitude: '', textData: {}, dome:false }, onLoad: function() { var that = this; wx.getLocation({ type: 'wgs84', success: (res) => { console.log(res); that.setData({ latitude: res.latitude, longitude: res.longitude }) var marker = [{ id: 1, latitude: res.latitude, longitude: res.longitude, iconPath: "../../images/marker.png", width: 22, height: 32, callout: { content: "你的位置\n换行内容", color: "#333333", fontSize: 13, borderRadius: 20, bgColor: "#ffffff", textAlign: "center" , padding: 10, display: 'ALWAYS' } }] that.setData({ markers: marker }); that.setData({ dome: true }); }, }); }, })

页面部分



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3