微信小程序获取当前位置并自定义浮窗

1、在腾讯地图api申请key(添加微信小程序的appid)。

每个Key每日可以免费使用100次,超过次数后会导致地图不显示。可以多申请几个Key解决。
WebService API | 腾讯位置服务腾讯地图开放平台为各类应用厂商和开发者提供基于腾讯地图的地理位置服务和解决方案;有针对Web应用的JavaScript API, 适合手机端Native APP的各种SDK, WebService接口和各类地图API等。https://lbs.qq.com/service/webService/webServiceGuide/overview

2、 先创建应用

3、 注意:域名白名单一定要填写,否则会导致地图不显示。

4、在uniapp小程序文件重添加权限和腾讯地图的文件.因为微信需要授权位置

5、设置地图浮窗(直接调用即可)

getLocation() {

const vm = this

vm.markers = \[\]

const qqmapsdk = new QQMapWX({

key: '你的key'

});

wx.getLocation({

type: 'wgs84',

isHighAccuracy: true,

success(res) {

qqmapsdk.reverseGeocoder({

location: {

latitude: res.latitude,

longitude: res.longitude

},

coord_type: 1,

get_poi: 1,

poi_options: 'policy=2;radius=600;page_size=20;page_index=1',

success: (r) => {

vm.latitude = r.result.location.lat,

vm.longitude = r.result.location.lng

const makerObj = {

iconPath: "图片地址",

longitude: vm.longitude,

latitude: vm.latitude,

id: 0,

width: 46,

height: 56,

callout: {

content: '当前位置',

color: '#ff0000',

fontSize: 14,

borderWidth: 2,

borderRadius: 10,

borderColor: '#000000',

bgColor: '#fff',

padding: 5,

display: 'ALWAYS',

textAlign: 'center'

},

}

vm.markers.push(makerObj)

},

fail: function(res) {}

});

}

});

},

6、地图展示

<map id="myMap" :markers="markers" style="width:100%;height:90%;"

:longitude="longitude" :latitude="latitude" show-location scale="18" @markertap="markertap">

</map>

相关推荐
spmcor1 天前
微信小程序 setStorageSync 踩坑实录:别让"顺手一存"变成"隐形炸弹"
微信小程序
用户4324281061142 天前
小程序埋点设计规范:如何设计可扩展的数据采集体系
微信小程序
m0_526119402 天前
iconfont我修改好颜色,但是在小程序项目是黑色的
小程序
2601_956743683 天前
2026 上海小程序开发甄选:源码、云函数、跨端兼容技术评判
小程序·开发经验·上海
IT_张三3 天前
CSDN-项目分享-暑期备考小程序
小程序
IsJunJianXin3 天前
pdd小程序 cdp 保存响应体
linux·服务器·小程序·pdd小程序·拼多多响应体解密·小程序cdp·拼多多rpc取响应体
Geek_Vison3 天前
APP瘦身实战:从80MB+砍到15MB——基于小程序容器技术剥离APP非核心业务的实践分享
小程序·uni-app·mpaas
weikecms3 天前
聚合返利CPS小程序快速搭建教程
人工智能·微信·小程序
Haibakeji4 天前
长沙餐饮门店点餐配送小程序定制开发
大数据·小程序
2501_915918414 天前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview