热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

港口定位项目开发笔记2·微信小程序端

港口定位项目开发笔记2微信小程序端点击按钮获取在地图上查看自己的位置微信小程序开发中解决位置授权问题点击按钮获取在地图上查看自己的位置demo.wxml

港口定位项目开发笔记2·微信小程序端


点击按钮获取在地图上查看自己的位置


微信小程序开发中解决位置授权问题


点击按钮获取在地图上查看自己的位置

demo.wxml

<view class="title">使用微信内置地图查看位置view>
<button type="primary" bindtap="openLoca">查看当前位置button>

demo.wxss

"title">使用微信内置地图查看位置

demo.js

openLoca(){wx.getLocation({type: &#39;gcj02&#39;, //返回可以用于wx.openLocation的经纬度success (res) {const latitude = res.latitudeconst longitude = res.longitudewx.openLocation({latitude,longitude,scale: 18})}})},
点击查看当前位置即可 #### 微信小程序开发中解决位置授权问题 上篇文章中介绍了如何获取当前位置的代码,但是很多时候用户不会自己打开位置授权,所以我们需要提示用户打开位置授权功能。

wx.getLocation({success: res => {console.log(res);},fail: e => {console.log(e);// 判断用户是否拒绝了授权wx.getSetting({success: res => {if (typeof(res.authSetting[&#39;scope.userLocation&#39;]) != &#39;undefined&#39; && !res.authSetting[&#39;scope.userLocation&#39;]) {// 用户拒绝了授权wx.showModal({title: &#39;提示&#39;,content: &#39;您拒绝了定位权限,将无法使用XX功能&#39;,success: res => {if (res.confirm) {// 跳转设置页面wx.openSetting({success: res => {if (res.authSetting[&#39;scope.userLocation&#39;]) {// 授权成功,重新定位wx.getLocation({success: res => {}});} else {// 没有允许定位权限wx.showToast({title: &#39;您拒绝了定位权限,将无法使用XX功能&#39;,icon: &#39;none&#39;});}}});}}});}}});}})

在这里插入图片描述


推荐阅读
author-avatar
连向明
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有