当前位置:网站首页>腾讯地图获取定位
腾讯地图获取定位
2022-08-09 02:22:00 【_格鲁特宝宝】
// 获取定位
// 方法一
getMyLocation() {
var geolocation = new qq.maps.Geolocation("CQPBZ-QRWCU-2RGVJ-44CGR-5WCY6-WVB5Q", "myapp_ay");
geolocation.getIpLocation(
(position) => {
console.log(position);
this.getAddress(position.lat, position.lng)
},
(err) => {
console.log("定位失败");
this.autoLocation = '安阳市';
this.getMyLocation();
},
);
// geolocation.getIpLocation(this.showPosition, this.showErr);
},
showPosition(position) {
console.log(position);
this.autoLocation = position.addr || position.city || '安阳市';
},
showErr() {
console.log("定位失败");
this.autoLocation = '安阳市';
this.getMyLocation(); //定位失败再请求定位,测试使用
},
// 方法二
getPosition(){
let vm = this
let data = {
key: "CQPBZ-QRWCU-2RGVJ-44CGR-5WCY6-WVB5Q", //申请的密钥
output: "jsonp",
};
let url = "https://apis.map.qq.com/ws/location/v1/ip"
this.$jsonp(url, data).then(res => {
console.log(res)
}).catch(err => {
this.$toast(err.message)
})
},
// 方法三
getCurLocation() {
var geolocation = new qq.maps.Geolocation("CQPBZ-QRWCU-2RGVJ-44CGR-5WCY6-WVB5Q", "myapp_ay");
/**
* getLocation(sucCallback, errCallback, [options: {timeout: number, failTipFlag: boolean}])
* sucCallback为定位成功回调函数,必填;
* errCallback为定位失败回调函数,选填,如果不填,请设为null;
* options为定位选项,选填,可以通过timeout参数设置定位的超时时间,默认值为10s;
* failTipFlag: 是否在定位失败时给出提示引导用户打开授权或打开定位开关。(即将支持)
*/
var options = {
timeout: 10000,
failTipFlag: true
};
geolocation.getLocation(
function (position) {
console.log(position);
},
null,
options
);
},
边栏推荐
猜你喜欢
MT4/MQL4入门到精通外汇EA教程第一课 认识MetaEditor
spdlog日志库的封装使用
MySQL/Oracle字符串分割
Likou Brush Question Record 5.1-----59. Spiral Matrix II
中国SSD产业突围有多难?除了技术“瓶颈”还有哪里挑战?
最强分布式锁工具:Redisson
数据库设计的总结
gpio子系统和pinctrl子系统(中)
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
力扣刷题记录3.1-----977. 有序数组的平方
随机推荐
HCIP-R&S By Wakin自用笔记(3)OSPF之各类LSA及LSA更新规则
Go-8-Gin framework
OpenMLDB + Jupyter Notebook:快速搭建机器学习应用
USB 触摸在竖屏时校准
[C language brush questions] Application of fast and slow pointers in linked lists
2022/8/8 比赛思维+状压dp
全志通过fastboot烧写boot.img
Redis系列文章导航
10.1-----19. Delete the Nth node from the bottom of the linked list
如何在推荐系统中玩转知识图谱
C#计算SHA1加密和base64编码
Open3D 随机采样
How to play knowledge graph in recommender system
年金险的安全性怎么样啊?可靠吗?
A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
Mysql 5.7 into the pit
力扣刷题记录6.1-----203. 移除链表元素
ApiFile配置环境
How js implements array deduplication (7 kinds)
D. Tournament Countdown