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

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>

相关推荐
weixin_lynhgworld13 小时前
旧物新生,从二手回收小程序开启绿色生活
小程序·生活·旧物回收
從南走到北15 小时前
智尚招聘求职小程序v1.0.23
微信小程序·小程序
2501_9159184119 小时前
掌握 iOS 26 App 运行状况,多工具协作下的监控策略
android·ios·小程序·https·uni-app·iphone·webview
知识分享小能手19 小时前
uni-app 入门学习教程,从入门到精通,uni-app基础扩展 —— 详细知识点与案例(3)
vue.js·学习·ui·微信小程序·小程序·uni-app·编程
2501_915909061 天前
iOS 混淆实战,多工具组合完成 IPA 混淆与加固(源码 + 成品 + 运维一体化方案)
android·运维·ios·小程序·uni-app·iphone·webview
狂团商城小师妹1 天前
智尚房产中介小程序
微信小程序·小程序
狂团商城小师妹1 天前
预约洗车小程序
微信小程序·小程序
future_studio1 天前
聊聊 Unity(小白专享、C# 小程序 之 图片播放器)
unity·小程序·c#
Q_Q5110082851 天前
python+uniapp基于微信小程序的心理咨询信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
HuYi_code1 天前
WeChat 小程序下载文件实现
微信小程序·uni-app