|
@@ -132,15 +132,15 @@ export default {
|
|
|
this.geolocation = new AMap.Geolocation({
|
|
|
enableHighAccuracy: true, // 高精度定位
|
|
|
timeout: 3000, // 定位超时时间
|
|
|
- // zoomToAccuracy: true, // 定位成功后再调整视野
|
|
|
+ zoomToAccuracy: true, // 定位成功后再调整视野
|
|
|
showCircle: false, // 定位成功有个圆形范围
|
|
|
showButton: false // 是否显示按钮
|
|
|
})
|
|
|
const locationRes = await this.getLocation(this.geolocation)
|
|
|
// 当前定位
|
|
|
if (locationRes.status === 'complete') {
|
|
|
- this.form.longitude = locationRes.data.position.lng
|
|
|
- this.form.latitude = locationRes.data.position.lat
|
|
|
+ this.form.longitude = locationRes.data.lng
|
|
|
+ this.form.latitude = locationRes.data.lat
|
|
|
}
|
|
|
// 获取城市信息
|
|
|
this.getGeocoder([this.form.longitude, this.form.latitude], locationRes.status)
|
|
@@ -177,14 +177,28 @@ export default {
|
|
|
// 获取定位
|
|
|
getLocation(geolocation) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- this.AMap.plugin('AMap.Geolocation', function () {
|
|
|
- geolocation.getCurrentPosition(function (status, res) {
|
|
|
+ try {
|
|
|
+ mapLocation.postMessage('获取定位')
|
|
|
+ window['setMapLocation'] = res => {
|
|
|
+ let e = JSON.parse(res)
|
|
|
resolve({
|
|
|
- status: status,
|
|
|
- data: res
|
|
|
+ status: 'complete',
|
|
|
+ data: {
|
|
|
+ lng: e.longitude,
|
|
|
+ lat: e.latitude
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ this.AMap.plugin('AMap.Geolocation', function () {
|
|
|
+ geolocation.getCurrentPosition(function (status, res) {
|
|
|
+ resolve({
|
|
|
+ status: status,
|
|
|
+ data: res.position
|
|
|
+ })
|
|
|
})
|
|
|
})
|
|
|
- })
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
|