// 获取定位
// 方法一
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 => {
腾讯地图获取定位
最新推荐文章于 2025-05-27 17:03:00 发布