uniapp使用谷歌地图获取位置

最近在使用uniapp开发的时候,由于客户是国外的,要求使用谷歌地图获取位置,所以找了一下实现的方法

首先在需要在需要使用地图的页面引入

bash 复制代码
let that = this
uni.getLocation({
        type: "wgs84",
        success: function (res) {
          console.log("当前位置的经度:" + res.longitude);
          console.log("当前位置的纬度:" + res.latitude);
          console.log(res.latitude, res.longitude, "res", res);
         
          const latlng = {
            lat: res.latitude,
            lng: res.longitude,
          };
          // 根据经纬度获取地址信息
          const apiKey = "api的key";
          const url = `https://maps.googleapis.com/maps/api/geocode/json?latlng=${res.latitude},${res.longitude}&key=api的key`;
          console.log(url);
          uni.request({
            url: 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + res.latitude + ',' + res.longitude + '&key=' + apiKey,
            method: "GET",
            success: (res2) => {
              console.log(res2)
            },
            fail: (err) => {
              // 处理网络错误
              this.errorMessage = `网络请求失败: ${err.errMsg}`;
            },
            complete: () => {
              // 请求完成后的操作
            },
          });
        },
      });

有相同问题的小伙伴可以试一下

希望可以帮到你~~

看到这如果对你有帮助的话

请用你发财的小手点赞加关注叭~

加个关注不迷路~

相关推荐
2501_9159184114 小时前
掌握 iOS 26 App 运行状况,多工具协作下的监控策略
android·ios·小程序·https·uni-app·iphone·webview
知识分享小能手14 小时前
uni-app 入门学习教程,从入门到精通,uni-app基础扩展 —— 详细知识点与案例(3)
vue.js·学习·ui·微信小程序·小程序·uni-app·编程
2501_9159090616 小时前
iOS 混淆实战,多工具组合完成 IPA 混淆与加固(源码 + 成品 + 运维一体化方案)
android·运维·ios·小程序·uni-app·iphone·webview
赵庆明老师17 小时前
Uniapp微信小程序开发:EF Core 中级联删除
uni-app
Javashop_jjj18 小时前
三勾软件| 用SpringBoot+Element-UI+UniApp+Redis+MySQL打造的点餐连锁系统
spring boot·ui·uni-app
Q_Q5110082851 天前
python+uniapp基于微信小程序的心理咨询信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
HuYi_code1 天前
WeChat 小程序下载文件实现
微信小程序·uni-app
00后程序员张1 天前
HTTPS 包 抓取与分析实战,从抓包到解密、故障定位与真机取证
网络协议·http·ios·小程序·https·uni-app·iphone
2501_915921431 天前
iOS混淆与IPA加固实战手记,如何构建苹果应用防反编译体系
android·macos·ios·小程序·uni-app·cocoa·iphone
Q_Q5110082851 天前
python+uniapp基于微信小程序的学院设备报修系统
spring boot·python·微信小程序·django·flask·uni-app