今天开始搞这个东西,下面是详细的记录

先看一下效果啦

1.小程序代码先获取用户基础位置信息

js

data: {
myLocation: 'GET LOCATION',
},
openMap() {
var myThis = this
wx.getLocation({
type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: function (res) {
// success
console.log('获取位置2');
myThis.setData({
myLocation: JSON.stringify(res)
})
console.log(res.latitude);
console.log(res.longitude); wx.openLocation({
latitude: res.latitude, // 纬度,范围为-90~90,负数表示南纬
longitude: res.longitude, // 经度,范围为-180~180,负数表示西经
scale: 28, // 缩放比例
name: "要找的地方名字(某某饭店)",
address: "地址:要去的地点详细描述"
})
}
})
},
openMap1() {
var myThis = this
wx.getLocation({
type: 'wgs84',
success(res) {
// 纬度,范围为 -90~90,负数表示南纬
const latitude = res.latitude
// 经度,范围为 -180~180,负数表示西经
const longitude = res.longitude
// 速度,单位 m/s
const speed = res.speed
// 位置的精确度,反应与真实位置之间的接近程度,可以理解成10即与真实位置相差10m,越小越精确
const accuracy = res.accuracy
myThis.setData({
myLocation: '当前经度:' + latitude + '\n' + '当前纬度:' + longitude + '\n' + '当前速度:' + speed + '\n' + '当前位置精确度:' + accuracy
})
console.log(res.latitude);
console.log(res.longitude);
}
})
},

html

 <button type="default" bindtap="openMap">点击打开地图</button>
<button type="default" bindtap="openMap1">点击获取我的位置</button>
<text >{{myLocation}}</text>

app.json

"pages": [
"pages/index/index"
],
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},

下面开始调用腾讯地图API进行解析我们的经纬度

注册账号

点此进入腾讯地图文档



创建应用,获取KEY,







发请求进行经纬度解析







JS

最新文章

  1. 『.NET Core CLI工具文档』(一).NET Core 命令行工具(CLI)
  2. python(1)
  3. iOS 直播(一)
  4. iOS -iPhone5、iPhone5s、iPhone6、iPhone6Plus 屏幕适配
  5. 1934: [Shoi2007]Vote 善意的投票 - BZOJ
  6. SQL Server 之 DBCC
  7. 多校7 HDU5816 Hearthstone 状压DP+全排列
  8. hdoj 1276 士兵队列训练问题【模拟】
  9. zabbix PHP databases support off Fail
  10. UML语言中五大视图和九种图形纵览
  11. 图像的膨胀与腐蚀——OpenCV与C++的具体实现
  12. python模块之configparse模块
  13. Lintcode225-Find Node in Linked List-Naive
  14. AIDL基本使用
  15. linux inotify 文件变化检测
  16. spring boot 日志介绍 以及 logback配置示例
  17. [CocoaPods]使用CocoaPods进行测试
  18. 【洛谷】【计数原理+Floyed】P1037 产生数
  19. extern的作用
  20. javascript数据结构与算法---二叉树(查找最小值、最大值、给定值)

热门文章

  1. day02-HTML02
  2. 谷歌拼音自带lua
  3. 河北首家城商行传统核心业务国产化,TDSQL突破三“最”为秦皇岛银行保驾护航
  4. 嵌入式-c语言基础:冒泡排序实现从大到小排列
  5. Quartz的使用
  6. 强软弱引用,ThreadLocal和内存泄漏
  7. vcenter异常死机无法重启
  8. centos8安装vsftpd
  9. 图文详解在VMware Workstation 16 PRO虚拟机上安装Ubuntu 22.04.5 linux系统
  10. ubuntu 20.04 / 22.04 运行32位程序