Squashed commit of the following:
commitf9e9899e0eAuthor: 浅念 <email@sample.com> Date: Fri Mar 28 11:10:56 2025 +0800 设置默认语言为英语 commit303121ba81Author: 浅念 <email@sample.com> Date: Fri Mar 28 11:00:05 2025 +0800 调用接口调整 commit37e0e55d96Author: 浅念 <email@sample.com> Date: Fri Mar 28 10:33:48 2025 +0800 线上接口地址 commit11dd7de521Author: 浅念 <email@sample.com> Date: Thu Mar 27 16:54:52 2025 +0800 修改样式 commit8ceb98b321Author: 浅念 <email@sample.com> Date: Thu Mar 27 16:47:04 2025 +0800 隐藏我的名片 commitf58e712684Author: 浅念 <email@sample.com> Date: Thu Mar 27 16:44:43 2025 +0800 样式调整 commit54ad6c9e37Author: 浅念 <email@sample.com> Date: Thu Mar 27 16:35:21 2025 +0800 修改语言包 commit526f934a75Author: 浅念 <email@sample.com> Date: Thu Mar 27 16:13:47 2025 +0800 标签功能 commit8583ff2543Author: 浅念 <email@sample.com> Date: Wed Mar 26 17:02:04 2025 +0800 标签管理页面 commitbe8674fd51Author: 浅念 <email@sample.com> Date: Tue Mar 25 17:29:37 2025 +0800 样式调整 commita5d5ce4e7cAuthor: 浅念 <email@sample.com> Date: Tue Mar 25 17:23:40 2025 +0800 倒计时组件 commitf88048b876Author: 浅念 <email@sample.com> Date: Tue Mar 25 17:19:43 2025 +0800 首页添加跟进提醒 commitf9a39d5aaaAuthor: 浅念 <email@sample.com> Date: Tue Mar 25 13:13:39 2025 +0800 提交 commite3abe0bf18Author: 浅念 <email@sample.com> Date: Tue Mar 25 13:12:24 2025 +0800 名片部分页面。地图定位。国家下拉搜索 回收站
This commit is contained in:
+118
-52
@@ -31,6 +31,7 @@ export default {
|
||||
value: '',
|
||||
// 模糊匹配数据
|
||||
list: [],
|
||||
center: { lat:'', lng:''},
|
||||
cityInfo:{
|
||||
lat: '',
|
||||
lng: '',
|
||||
@@ -44,7 +45,12 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
onLoad(e) {
|
||||
if(e.lat&&e.lat!=''&&e.lat!=0){
|
||||
this.center.lat = e.lat
|
||||
this.center.lng = e.lng
|
||||
}
|
||||
console.log(e)
|
||||
this.initMap()
|
||||
},
|
||||
methods:{
|
||||
@@ -92,63 +98,123 @@ export default {
|
||||
});
|
||||
that.list =[]
|
||||
},
|
||||
getErrorMessage(error) {
|
||||
switch (error.code) {
|
||||
case error.PERMISSION_DENIED:
|
||||
return "用户拒绝了地理位置权限";
|
||||
case error.POSITION_UNAVAILABLE:
|
||||
return "无法获取当前位置";
|
||||
case error.TIMEOUT:
|
||||
return "获取位置超时";
|
||||
default:
|
||||
return "未知错误";
|
||||
}
|
||||
},
|
||||
addmapmarkfn(lat,lng){
|
||||
var that = this
|
||||
that.map = new google.maps.Map(document.getElementById("map"),
|
||||
{
|
||||
center: { lat:lat, lng: lng},
|
||||
zoom: 12,// 地图缩放参数
|
||||
maxZoom: 18,// 最大缩放参数
|
||||
minZoom: 4,// 最小缩放参数
|
||||
disableDefaultUI: true// 禁用默认UI
|
||||
}
|
||||
)
|
||||
var marker = new google.maps.Marker({
|
||||
position: { lat:lat, lng: lng},
|
||||
map: that.map,
|
||||
draggable: true, // 允许拖动标记
|
||||
icon: {
|
||||
url: 'https://now.guua.com/attachs/default/location_shop.png',
|
||||
scaledSize: new google.maps.Size(30, 30),
|
||||
origin: new google.maps.Point(0, 0),
|
||||
anchor: new google.maps.Point(0, 0)
|
||||
}
|
||||
});
|
||||
// 监听标记拖动事件
|
||||
marker.addListener('dragend', () => {
|
||||
const position = marker.getPosition();
|
||||
that.map.setCenter(position);
|
||||
// 根据标记位置获取地址信息
|
||||
const geocoder = new google.maps.Geocoder();
|
||||
geocoder.geocode({ location: position }, (results, status) => {
|
||||
if (status === 'OK' && results[0]) {
|
||||
console.log(results)
|
||||
console.log(position)
|
||||
that.cityInfo.address = results[0].formatted_address;
|
||||
that.cityInfo.lat = position.lat();
|
||||
that.cityInfo.lng = position.lng();
|
||||
that.value = results[0].formatted_address;
|
||||
console.log(that.cityInfo)
|
||||
} else {
|
||||
alert('无法获取地址信息');
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
unigetLocation(){
|
||||
var that = this
|
||||
uni.getLocation({
|
||||
type: 'wgs84', // 默认为 wgs84 坐标系,可选 gcj02
|
||||
success: function (res) {
|
||||
console.log('当前位置的经度:' + res.longitude);
|
||||
console.log('当前位置的纬度:' + res.latitude);
|
||||
that.addmapmarkfn(res.latitude,res.longitude)
|
||||
// 如果需要将经纬度转换为具体地址,可以使用逆地理编码
|
||||
// 这里调用 uni.chooseLocation 或第三方地图服务(如高德、腾讯地图)
|
||||
},
|
||||
fail: function (err) {
|
||||
console.log('获取位置失败:', err);
|
||||
},
|
||||
complete: function () {
|
||||
console.log('获取位置完成');
|
||||
}
|
||||
});
|
||||
},
|
||||
initMap() {
|
||||
var that = this
|
||||
loader
|
||||
.load()
|
||||
.then((google) => {
|
||||
uni.getLocation({
|
||||
type: 'wgs84', // 默认为 wgs84 坐标系,可选 gcj02
|
||||
success: function (res) {
|
||||
console.log(res)
|
||||
that.map = new google.maps.Map(document.getElementById("map"),
|
||||
{
|
||||
center: { lat:res.latitude, lng: res.longitude},
|
||||
zoom: 12,// 地图缩放参数
|
||||
maxZoom: 18,// 最大缩放参数
|
||||
minZoom: 4,// 最小缩放参数
|
||||
disableDefaultUI: true// 禁用默认UI
|
||||
}
|
||||
)
|
||||
var marker = new google.maps.Marker({
|
||||
position: { lat:res.latitude, lng: res.longitude},
|
||||
map: that.map,
|
||||
draggable: true, // 允许拖动标记
|
||||
icon: {
|
||||
url: 'https://now.guua.com/attachs/default/location_shop.png',
|
||||
scaledSize: new google.maps.Size(30, 30),
|
||||
origin: new google.maps.Point(0, 0),
|
||||
anchor: new google.maps.Point(0, 0)
|
||||
if(this.center.lat!=''){
|
||||
that.addmapmarkfn(parseFloat(this.center.lat),parseFloat(this.center.lng))
|
||||
}else{
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(position) => {
|
||||
console.log('当前位置的经度:' + position.coords.longitude);
|
||||
console.log('当前位置的纬度:' + position.coords.latitude);
|
||||
that.addmapmarkfn(position.coords.latitude,position.coords.longitude)
|
||||
this.error = '';
|
||||
console.log("获取位置成功:", position);
|
||||
},
|
||||
(error) => {
|
||||
that.unigetLocation()
|
||||
// this.error = this.getErrorMessage(error);
|
||||
// uni.showToast({
|
||||
// title: this.error,
|
||||
// icon: 'none'
|
||||
// });
|
||||
console.error("获取位置失败:", error);
|
||||
},
|
||||
{
|
||||
enableHighAccuracy: true,
|
||||
timeout: 10000,
|
||||
maximumAge: 0
|
||||
}
|
||||
});
|
||||
// 监听标记拖动事件
|
||||
marker.addListener('dragend', () => {
|
||||
const position = marker.getPosition();
|
||||
that.map.setCenter(position);
|
||||
// 根据标记位置获取地址信息
|
||||
const geocoder = new google.maps.Geocoder();
|
||||
geocoder.geocode({ location: position }, (results, status) => {
|
||||
if (status === 'OK' && results[0]) {
|
||||
console.log(results)
|
||||
console.log(position)
|
||||
that.cityInfo.address = results[0].formatted_address;
|
||||
that.cityInfo.lat = position.lat();
|
||||
that.cityInfo.lng = position.lng();
|
||||
that.value = results[0].formatted_address;
|
||||
console.log(that.cityInfo)
|
||||
} else {
|
||||
alert('无法获取地址信息');
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
fail: function (err) {
|
||||
console.log('获取位置失败:', err);
|
||||
},
|
||||
complete: function () {
|
||||
console.log('获取位置完成');
|
||||
}
|
||||
})
|
||||
);
|
||||
} else {
|
||||
that.unigetLocation()
|
||||
// this.error = "浏览器不支持 Geolocation API";
|
||||
// uni.showToast({
|
||||
// title: this.error,
|
||||
// icon: 'none'
|
||||
// });
|
||||
console.error("浏览器不支持 Geolocation API");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
.catch((e) => {
|
||||
|
||||
Reference in New Issue
Block a user