腾讯地图定位

This commit is contained in:
zxy
2024-02-04 22:34:37 +08:00
parent 966439f8d6
commit ca50d9cab0
3 changed files with 50 additions and 51 deletions

View File

@@ -1,25 +1,25 @@
import request from '@/router/axios';
import request from "@/router/axios";
/*逆地址解析*/
export const getcoder = (location, key, get_poi) => {
return request({
url: '/api/map/ws/geocoder/v1',
method: 'get',
url: "/qq/map/ws/geocoder/v1",
method: "get",
params: {
location,
key,
get_poi
}
})
}
});
};
/*关键词输入提示*/
export const querySearch = (keyword, key) => {
return request({
url: '/api/map/ws/place/v1/suggestion',
method: 'get',
url: "/qq/map/ws/place/v1/suggestion",
method: "get",
params: {
keyword,
key
}
})
}
});
};

View File

@@ -33,18 +33,18 @@ export default {
props: {
lat: {
type: "string",
default: 23.1315381,
default: 23.1315381
},
lng: {
type: "string",
default: 113.3324436,
default: 113.3324436
},
address: String,
isCanEdit: Boolean,
type: {
type: "string",
default: "",
},
default: ""
}
},
data() {
return {
@@ -53,8 +53,8 @@ export default {
map2: "", // 地图实例
mk2: "", // Marker实例,
addressLocation: this.address,
key: "FW3BZ-6JTK6-GCUS5-MZCRR-3GPR5-HJFEI",
addressTip: [],
key: "MTCBZ-WAAWC-H3M22-AL6XI-G4XN6-YZFK5",
addressTip: []
};
},
mounted() {
@@ -64,9 +64,8 @@ export default {
methods: {
addressChangeHandle(val) {
if (val == "") {
this.$emit('addressDel',"删除了地址数据")
this.$emit("addressDel", "删除了地址数据");
}
},
// 初始化地图
initMap() {
@@ -82,17 +81,17 @@ export default {
zoomControl: true,
//地图缩放控件参数
zoomControlOptions: {
position: qq.maps.ControlPosition.TOP_LEFT,
position: qq.maps.ControlPosition.TOP_LEFT
},
//地图比例尺控件若为false则不显示比例尺控件
scaleControl: false,
scaleControl: false
});
// 3、设置图像标注并绑定拖拽标注结束后事件
this.mk = new qq.maps.Marker({
position: point,
draggable: true,
map: that.map,
map: that.map
});
// 绑定拖拽标注结束后事件
qq.maps.event.addListener(this.mk, "dragend", function(e) {
@@ -114,16 +113,16 @@ export default {
zoom: 19,
//地图缩放控件参数
zoomControlOptions: {
position: qq.maps.ControlPosition.TOP_LEFT,
position: qq.maps.ControlPosition.TOP_LEFT
},
//地图比例尺控件若为false则不显示比例尺控件
scaleControl: false,
scaleControl: false
});
// 2、设置图像标注并绑定拖拽标注结束后事件
this.mk2 = new qq.maps.Marker({
position: point2,
draggable: false,
map: that.map2,
map: that.map2
});
}
},
@@ -131,18 +130,18 @@ export default {
geolocation() {
var that = this;
var geolocation = new qq.maps.Geolocation(
"FW3BZ-6JTK6-GCUS5-MZCRR-3GPR5-HJFEI",
"jobslink 企业"
"MTCBZ-WAAWC-H3M22-AL6XI-G4XN6-YZFK5",
"后台管理"
);
geolocation.getLocation(this.showPosition, this.showErr, {
timeout: 20000,
failTipFlag: true,
failTipFlag: true
});
},
showPosition(position) {
this.getAddrByPoint({
lat: position.lat,
lng: position.lng,
lng: position.lng
});
},
showErr() {
@@ -153,20 +152,20 @@ export default {
var currentPoint = new qq.maps.LatLng(point.lat, point.lng);
var that = this;
var location = point.lat + "," + point.lng;
getcoder(location, encodeURI(this.key), 0).then((res) => {
getcoder(location, encodeURI(this.key), 0).then(res => {
that.mk.setPosition(currentPoint);
that.map.panTo(currentPoint);
let obj = {
address: res.data.result.address,
lng: point.lng,
lat: point.lat,
lat: point.lat
};
that.addressLocation = obj.address
that.addressLocation = obj.address;
that.$emit("addAddress", obj);
});
},
async querySearchAsync(queryString, cb) {
await querySearch(queryString, encodeURI(this.key)).then((res) => {
await querySearch(queryString, encodeURI(this.key)).then(res => {
if (res.data.status === 0) {
this.addressTip = res.data.data;
}
@@ -188,11 +187,11 @@ export default {
title: item.title,
address: item.address,
lng: item.location.lng,
lat: item.location.lat,
lat: item.location.lat
};
this.$emit("addAddress", obj);
},
},
}
}
};
</script>

View File

@@ -31,12 +31,12 @@ module.exports = {
"^/api": "/"
}
},
"/api/map": {
"/qq/map": {
//本地服务接口地址
target: "http://apis.map.qq.com",
target: "https://apis.map.qq.com",
ws: true,
pathRewrite: {
"^/api/map": "/"
"^/qq/map": "/"
}
}
}