|
|
@ -425,7 +425,6 @@ export default { |
|
|
this.chooseCommunity(); |
|
|
this.chooseCommunity(); |
|
|
}, |
|
|
}, |
|
|
getLocation() { |
|
|
getLocation() { |
|
|
// let get = async () => { |
|
|
|
|
|
//判断是否在微信环境下操作 |
|
|
//判断是否在微信环境下操作 |
|
|
var ua = window.navigator.userAgent.toLowerCase(); |
|
|
var ua = window.navigator.userAgent.toLowerCase(); |
|
|
//通过正则表达式匹配ua中是否含有MicroMessenger字符串 |
|
|
//通过正则表达式匹配ua中是否含有MicroMessenger字符串 |
|
|
@ -436,21 +435,10 @@ export default { |
|
|
this.getId(); |
|
|
this.getId(); |
|
|
this.getAddressInfo(); |
|
|
this.getAddressInfo(); |
|
|
}); |
|
|
}); |
|
|
// this.getData().then(result => { |
|
|
|
|
|
// this.wxLocation({}) |
|
|
|
|
|
// }); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
// TODO 非微信环境用百度api |
|
|
// TODO 非微信环境用百度api |
|
|
this.getCity(); |
|
|
this.getCity(); |
|
|
} |
|
|
} |
|
|
// }; |
|
|
|
|
|
// return get(); |
|
|
|
|
|
}, |
|
|
|
|
|
getWXLocation() { |
|
|
|
|
|
let get = async () => { |
|
|
|
|
|
await this.wxLocation({}); |
|
|
|
|
|
}; |
|
|
|
|
|
return get(); |
|
|
|
|
|
}, |
|
|
}, |
|
|
getCity() { |
|
|
getCity() { |
|
|
let _this = this; |
|
|
let _this = this; |
|
|
@ -458,47 +446,94 @@ export default { |
|
|
|
|
|
|
|
|
geolocation.getCurrentPosition(function(r) { |
|
|
geolocation.getCurrentPosition(function(r) { |
|
|
if (this.getStatus() == BMAP_STATUS_SUCCESS) { |
|
|
if (this.getStatus() == BMAP_STATUS_SUCCESS) { |
|
|
// if(r.accuracy==null){ |
|
|
|
|
|
|
|
|
var lat = r.point.lat; |
|
|
|
|
|
var lng = r.point.lng; |
|
|
|
|
|
const pointBak = new BMap.Point(lng, lat); |
|
|
|
|
|
const convertor = new BMap.Convertor(); |
|
|
|
|
|
convertor.translate([pointBak], 1, 5, function(resPoint) { |
|
|
|
|
|
if (resPoint && resPoint.points && resPoint.points.length > 0) { |
|
|
|
|
|
console.log("resPoint:"+resPoint.points[0]); |
|
|
|
|
|
lng = resPoint.points[0].lng; |
|
|
|
|
|
lat = resPoint.points[0].lat; |
|
|
|
|
|
} |
|
|
|
|
|
const point = new BMap.Point(lng, lat); |
|
|
|
|
|
const geo = new BMap.Geocoder(); |
|
|
|
|
|
geo.getLocation(point, res => { |
|
|
|
|
|
if (res.addressComponents) { |
|
|
|
|
|
const result = res.addressComponents; |
|
|
|
|
|
const location = { |
|
|
|
|
|
creditLongitude: point.lng, // 经度 |
|
|
|
|
|
creditLatitude: point.lat, // 纬度 |
|
|
|
|
|
creditProvince: result.province || "", // 省 |
|
|
|
|
|
creditCity: result.city || "", // 市 |
|
|
|
|
|
creditArea: result.district || "", // 区 |
|
|
|
|
|
creditStreet: |
|
|
|
|
|
(result.street || "") + (result.streetNumber || "") // 街道 |
|
|
|
|
|
}; |
|
|
|
|
|
_this.location = location; |
|
|
|
|
|
localStorage.setItem("latitude", location.creditLatitude); |
|
|
|
|
|
localStorage.setItem("longitude", location.creditLongitude); |
|
|
|
|
|
_this.lat = location.creditLatitude; |
|
|
|
|
|
_this.lng = location.creditLongitude; |
|
|
|
|
|
alert( |
|
|
|
|
|
"省-" + |
|
|
|
|
|
location.creditProvince + |
|
|
|
|
|
";市-" + |
|
|
|
|
|
location.creditCity + |
|
|
|
|
|
";区-" + |
|
|
|
|
|
location.creditArea + |
|
|
|
|
|
";街道-" + |
|
|
|
|
|
location.creditStreet + |
|
|
|
|
|
";lat-" + |
|
|
|
|
|
location.creditLatitude + |
|
|
|
|
|
";lng-" + |
|
|
|
|
|
location.creditLongitude |
|
|
|
|
|
); |
|
|
|
|
|
_this.getId(); |
|
|
|
|
|
_this.getAddressInfo(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
// alert('您已拒绝地理位置授权'); |
|
|
// alert('您已拒绝地理位置授权'); |
|
|
// //用户决绝地理位置授权 |
|
|
// //用户决绝地理位置授权 |
|
|
// return; |
|
|
// return; |
|
|
// }else{ |
|
|
// }else{ |
|
|
const myGeo = new BMap.Geocoder(); |
|
|
|
|
|
myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), data => { |
|
|
|
|
|
if (data.addressComponents) { |
|
|
|
|
|
const result = data.addressComponents; |
|
|
|
|
|
const location = { |
|
|
|
|
|
creditLongitude: r.point.lng, // 经度 |
|
|
|
|
|
creditLatitude: r.point.lat, // 纬度 |
|
|
|
|
|
creditProvince: result.province || "", // 省 |
|
|
|
|
|
creditCity: result.city || "", // 市 |
|
|
|
|
|
creditArea: result.district || "", // 区 |
|
|
|
|
|
creditStreet: |
|
|
|
|
|
(result.street || "") + (result.streetNumber || "") // 街道 |
|
|
|
|
|
}; |
|
|
|
|
|
_this.location = location; |
|
|
|
|
|
localStorage.setItem("latitude", location.creditLatitude); |
|
|
|
|
|
localStorage.setItem("longitude", location.creditLongitude); |
|
|
|
|
|
_this.lat = location.creditLatitude; |
|
|
|
|
|
_this.lng = location.creditLongitude; |
|
|
|
|
|
alert( |
|
|
|
|
|
"省-" + |
|
|
|
|
|
location.creditProvince + |
|
|
|
|
|
";市-" + |
|
|
|
|
|
location.creditCity + |
|
|
|
|
|
";区-" + |
|
|
|
|
|
location.creditArea + |
|
|
|
|
|
";街道-" + |
|
|
|
|
|
location.creditStreet + |
|
|
|
|
|
";lat-" + |
|
|
|
|
|
location.creditLatitude + |
|
|
|
|
|
";lng-" + |
|
|
|
|
|
location.creditLongitude |
|
|
|
|
|
); |
|
|
|
|
|
_this.getId(); |
|
|
|
|
|
_this.getAddressInfo(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// const myGeo = new BMap.Geocoder(); |
|
|
|
|
|
// myGeo.getLocation(new BMap.Point(r.point.lng, r.point.lat), data => { |
|
|
|
|
|
// if (data.addressComponents) { |
|
|
|
|
|
// const result = data.addressComponents; |
|
|
|
|
|
// const location = { |
|
|
|
|
|
// creditLongitude: r.point.lng, // 经度 |
|
|
|
|
|
// creditLatitude: r.point.lat, // 纬度 |
|
|
|
|
|
// creditProvince: result.province || "", // 省 |
|
|
|
|
|
// creditCity: result.city || "", // 市 |
|
|
|
|
|
// creditArea: result.district || "", // 区 |
|
|
|
|
|
// creditStreet: |
|
|
|
|
|
// (result.street || "") + (result.streetNumber || "") // 街道 |
|
|
|
|
|
// }; |
|
|
|
|
|
// _this.location = location; |
|
|
|
|
|
// localStorage.setItem("latitude", location.creditLatitude); |
|
|
|
|
|
// localStorage.setItem("longitude", location.creditLongitude); |
|
|
|
|
|
// _this.lat = location.creditLatitude; |
|
|
|
|
|
// _this.lng = location.creditLongitude; |
|
|
|
|
|
// alert( |
|
|
|
|
|
// "省-" + |
|
|
|
|
|
// location.creditProvince + |
|
|
|
|
|
// ";市-" + |
|
|
|
|
|
// location.creditCity + |
|
|
|
|
|
// ";区-" + |
|
|
|
|
|
// location.creditArea + |
|
|
|
|
|
// ";街道-" + |
|
|
|
|
|
// location.creditStreet + |
|
|
|
|
|
// ";lat-" + |
|
|
|
|
|
// location.creditLatitude + |
|
|
|
|
|
// ";lng-" + |
|
|
|
|
|
// location.creditLongitude |
|
|
|
|
|
// ); |
|
|
|
|
|
// _this.getId(); |
|
|
|
|
|
// _this.getAddressInfo(); |
|
|
|
|
|
// } |
|
|
|
|
|
// }); |
|
|
// } |
|
|
// } |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|