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

相亲网站建设策划书范文本地网站搭建软件

相亲网站建设策划书范文,本地网站搭建软件,营销活动管理系统,做公司网站首页文章目录 uni.getLocation(objc)获取经纬度和地址调试结果问题 uni-app 获取当前位置的经纬度以及地址信息 uni.getLocation(objc) uni-app官方文档定位API: uni.getLocation(OBJECT) uni.getLocation({type: wgs84,success: function (res) {console.log(当前位置的经度&…

文章目录

    • uni.getLocation(objc)
    • 获取经纬度和地址
    • 调试结果
    • 问题

uni-app 获取当前位置的经纬度以及地址信息

uni.getLocation(objc)

uni-app官方文档定位API: uni.getLocation(OBJECT)

uni.getLocation({type: 'wgs84',success: function (res) {console.log('当前位置的经度:' + res.longitude);console.log('当前位置的纬度:' + res.latitude);}
});

获取经纬度和地址

  1. 去高德开放平台注册账号,添加应用,申请个AppKey

  2. 设置

1)配置勾选系统定位和高德定位,配置高德的“用户名”和“app key”
在这里插入图片描述

2)添加定位权限
在这里插入图片描述
<uses-permission android:name="android.permission.LOCATION"/>

  1. 上代码
<template><view class="container"><text class="title">定位示例</text><button @click="getLocation">获取经纬度</button><view v-if="location"><text>纬度: {{ location.latitude }}</text><text>经度: {{ location.longitude }}</text><text>速度: {{ location.speed }} m/s</text><text>精度: {{ location.accuracy }} m</text></view><view v-if="address"><text>位置: {{ address.formatted_address }} </text></view><view v-if="error"><text>错误信息: {{ error.message }}</text></view></view>
</template><script>
export default {data() {return {location: null,address: null,error: null};},methods: {getLocation() {uni.getLocation({type: 'wgs84',success: (res) => {this.location = {latitude: res.latitude,longitude: res.longitude,speed: res.speed,accuracy: res.accuracy,};this.reverseGeocode(res.latitude,res.longitude);console.log('定位成功:', res);},fail: (err) => {this.error = err;console.error('定位失败:', err);}});},// 逆地理编码函数reverseGeocode(latitude, longitude) {const key = '46XXXXXXXXXXXXXXXXXXXXXX0a'; // 换成你自己的AppKeyconst url = `https://restapi.amap.com/v3/geocode/regeo?key=${key}&location=${longitude},${latitude}`;uni.request({url: url,method: 'GET',success: (res) => {if (res.statusCode === 200 && res.data.status === '1') {this.address = {formatted_address: res.data.regeocode.formatted_address,};console.log(res.data.regeocode);} else {console.error('逆地理编码失败:', res.data);}},fail: (error) => {console.error('请求失败:', error);}});}},onLoad() {this.getLocation();}
};
</script><style>
.container {padding: 20px;
}.title {font-size: 20px;font-weight: bold;margin-bottom: 20px;
}button {margin-bottom: 20px;
}text {display: block;margin-bottom: 10px;
}
</style>

1)先调用uni.getLocation(objc) 函数可以拿到经纬度信息
2)再调用高德地图你地理编码的API获取经纬度对应的地址信息。

调试结果

在Safari上可以获取到经纬度和位置信息:

在这里插入图片描述

在Chrome上调试获取不到;

打包apk手机上也可以获取到经纬度和位置信息。

问题

1)uni.getLocation(objc) 这个函数有一个参数geocode

在这里插入图片描述
App上支持这个方法直接获取地址信息,需要设置 geocode 位 true,同时type参数需要设置成gcj02。

    getLocation() {uni.getLocation({type: 'gcj02',geocode: true,success: (res) => {this.location = {latitude: res.latitude,longitude: res.longitude,speed: res.speed,accuracy: res.accuracy,address: res.address,};console.log('定位成功:', res);},fail: (err) => {this.error = err;console.error('定位失败:', err);}});},

我试了试,手机打包可以获取到经纬度,但是位置信息没拿到,不知道是哪里的配置问题,示例如下:

在这里插入图片描述

在这里插入图片描述

http://www.yayakq.cn/news/366123/

相关文章:

  • 搜索引擎网站开发深圳市建设(集团)有限公司是国企吗
  • 网站建设公司的那些坑网站模板种类
  • 赤坎手机网站建设网络品牌前十大排名
  • 天猫官方网站做救助流浪动物网站的产生背景
  • 网站建设首先要学会什么wordpress电脑安装教程
  • 设计师常用网站门户redis 移动 wordpress
  • 淘宝客免费建网站网站建设合同严瑾
  • 购物网站设计开题报告景安服务器管理助手如何备份网站
  • 厦门网站建设公南京江北新区地图
  • 微信支付 网站建设网站建设数据库怎么弄
  • 什么网站可以做调察问卷客似云来网站建设
  • 公司网站优化外包36kr是用wordpress吗
  • 手机网站抢拍是怎么做的什么是网络营销调研
  • 兰州网站建设科技公司360免费建站391199
  • 本溪建设银行网站全国最大网站建设免费
  • 网站由哪些部分组成典型的软件开发模型
  • 阳春网站制作做问卷赚钱最好似网站
  • 安庆市网站建设公司wordpress 8211
  • 网站脚本错误网站建设初稿
  • 郑州做网站七彩科技仙霞新村街道网站建设
  • 毕设网站开发什么题目好怎么在网站做视频接口
  • 宁波网站制作网站优质的集团网站建设
  • 网页设计站点规划ps网站怎么做滑动背景图片
  • 网站制作乛薇网站备案转移
  • 网站主服务器地址世界建筑网
  • 电子商务网站建设与维护方法分析不包括十堰外贸网站建设
  • 陕西省网站开发快手app下载安装免费下载
  • 网站网页设计制作公司合肥做网站的
  • 泉州优化怎么做搜索网站建设优化石家庄
  • 莱芜建设局网站佳木斯 两学一做 网站