当前位置: 首页 > news >正文

Uni-app 调用微信地图导航功能【有图】

前言

我们在使用uni-app时,有时候会遇到需要开发地图和导航的功能,这些方法其实微信小程序的API已经帮我们封装好了
详见:微信小程序开发文档
接下来我们就演示如何用uni-app来使用他们

使用

<template><view><button type="primary" @click="chooseLocation" class="acc">选择位置 </button>经度:<span>{{longitude==' ' || longitude==null ?'/':longitude}}</span>纬度:<span>{{latitude==' ' || latitude==null ?'/':latitude}}</span><button type="default" @click="nav">导航 </button></view>
</template><script setup>import { getCurrentInstance, ref } from "vue";import { onBackPress } from "@dcloudio/uni-app";const { proxy } = getCurrentInstance();const name = ref(null)const address = ref(null)const latitude = ref(null)const longitude = ref(null)function nav() {uni.openLocation({latitude: latitude.value,longitude: longitude.value,name: name.value,scale: 15,address: address.value,success: function(res) {proxy.$modal.msgSuccess('打开地图成功!', res);},fail: function(error) {proxy.$modal.msgError('打开地图失败!', error);},});}function chooseLocation() {uni.chooseLocation({success: function(res) {name.value = res.name; // 位置名称address.value = res.address; // 详细地址latitude.value = res.latitude; // 纬度longitude.value = res.longitude; // 经度console.log('name', name.value);console.log('address', address.value);console.log('latitude', latitude.value);console.log('longitude', longitude.value);},fail: function(error) {console.error('选择位置失败', error);},});}// 获取当前位置的经纬度uni.getLocation({success: function(res) {var latitude = res.latitude; // 纬度var longitude = res.longitude; // 经度console.log('latitude', latitude);console.log('longitude', longitude);// 在这里可以将经纬度转换为地址信息,后续步骤中会介绍如何实现这一功能。},fail: function(error) {console.error('获取地理位置失败', error);},});// 页面加载onBackPress(() => {proxy.$tab.switchTab('/pages/office/index');return true;});
</script><style>.acc {margin-bottom: 20px;}
</style>

效果

进去后看到的效果
在这里插入图片描述
点击选择位置后
在这里插入图片描述
点击导航后
在这里插入图片描述
点击右下角的位置后,调用地图功能,会根据手机下载的软件来显示
如果手机内没有下载软件,会有腾讯地图和谷歌地图选项,点击会跳转到下载界面

在这里插入图片描述

http://www.lryc.cn/news/175135.html

相关文章:

  • Golang slice 通过growslice调用nextslicecap计算扩容
  • HTTP 协商缓存 Last-Modified,If-Modified-Since
  • 零基础教程:Yolov5模型改进-添加13种注意力机制
  • vue截取地址参数
  • ubuntu 14.04更新GCC版本
  • AndroidUtil - 强大易用的安卓工具类库
  • [多态设计模式]枚举
  • 【QT】QRadioButton的使用(17)
  • 力扣:105. 从前序与中序遍历序列构造二叉树(Python3)
  • 【含java2023面试题】HashMap、HashTable、ConcurrentHashMap
  • AT24C02芯片
  • Python+Django前后端分离
  • win11系统固定到快速访问的文件夹无法调整顺序的问题
  • 短视频矩阵系统,短视频矩阵源码技术开发
  • Flask 数据库 连接池、DBUtils、http 连接池
  • Day 01 python学习笔记
  • CSharp Library develop histroy
  • 林木种苗生产vr虚拟实训教学降低培训等待周期
  • LabVIEW在运行时调整表控件列宽
  • 【6 ElementUI Tabs控件第二个tab页签Div宽度缩小的问题】
  • 读写分离MySQL
  • MySQL数据库用户管理
  • package.json属性
  • C# 把m4a格式文件转为MP3格式
  • 【分享】Word文档如何批量转换成PDF?
  • dedecms tag 伪静态 数字版本
  • mysql数据库ip被阻断
  • Nginx WEB访问与Linux授权约束
  • 影响独立服务器稳定运行的因素
  • Xcode14.3.1打包报错Command PhaseScriptExecution failed with a nonzero exit code