当前位置:网站首页>uniapp---- 获取当前位置的经纬度等信息的详细步骤(包含小程序)
uniapp---- 获取当前位置的经纬度等信息的详细步骤(包含小程序)
2022-07-28 06:45:00 【In Heaven】
uniapp----获取当前位置的经纬度等信息的详细步骤(包含小程序)
1.在项目中进行配置,我选择的是高德地图,填写相关信息。

2.进入高德官网:https://lbs.amap.com/upgrade#quota,进行登录注册,进入到“控制台”。
3.打开 “应用管理” -> “我的应用”页面,点击“创建新应用”,根据页面提示填写内容创建应用。
4.在应用下点击“添加”为应用添加Key,根据需要分别为Android平台、iOS平台申请Key。
5.需要也申请一个微信小程序key,因为我的项目是先开发小程序,在uniapp的官方文档中有详细的介绍:
参考链接:https://ask.dcloud.net.cn/article/35070参考链接的步骤很详细可以直接进行项目编写。
import amap from '../../common/amap-wx.js';
export default {
data() {
return {
amapPlugin: null,
key: '高德key',
addressName: '',
weather: {
hasData: false,
data: []
}
}
},
onLoad() {
this.amapPlugin = new amap.AMapWX({
key: this.key
});
},
methods: {
getRegeo() {
uni.showLoading({
title: '获取信息中'
});
this.amapPlugin.getRegeo({
success: (data) => {
console.log(data)
this.addressName = data[0].name;
uni.hideLoading();
}
});
}
}
}
6.当uniapp项目在微信开发者工具打开时,需要再配置地图相关代码:
//开发过程中,需要在unpackage>>dist>>dev>>mp-weixin>>app.json中加入如下配置
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
//在manifest.json的源码视图中配置:配置appid和地理位置
"mp-weixin": {
/* 小程序特有相关 */
"appid": "", //需要配置appid
"setting": {
"urlCheck": false
},
"usingComponents": true,
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
}

边栏推荐
- How to close the blocked program process?
- Chairman tree review
- Meituan Er Mian: why does redis have sentinels?
- Matlab file path
- There are two Kafka topics that need to write data intact to MySQL King through Flink. Scheme 1: write two f's
- ASP. Net core foundation VIII
- Redis of non relational database [detailed setup of redis cluster]
- JS thoroughly understand this point
- Recommend a fully open source, feature rich, beautiful interface mall system
- File editing component
猜你喜欢
随机推荐
Es6: arrow function usage
A group of South University students rely on science and technology to go to sea, with an annual income of 1billion
EMC EMI磁珠的特性
Es6: template string
2021-07-02
leetcode/排序数组中两个数字之和
How to build the protection system of class protection technology of 2022 series of ISO compliance (Part I)
Deluxe H5 Tetris game source code
UE4 engine customizes screenpass and MRT output
Use of namespaces
Find out whether the number exists from the matrix
pyflink连接iceberg 实践
XSS知识点和20字符短域名绕过
js卡片层叠样式的图片切换js特效
What happens when you unplug the power? Gaussdb (for redis) dual life keeps you prepared
本人男,27岁技术经理,收入太高,心头慌得一比
PostgreSQL is the world's most advanced open source relational database
Oracle local network service
聊一聊数据库的行存与列存
QT 怎么删除布局里的所有控件?









