// 获取定位
// 方法一
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
);
},