export function initGeocoder() { return new Promise((resolve, reject) => { window.AMap.plugin('AMap.Geocoder', () => { try { const geocoder = new window.AMap.Geocoder({ // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode city: '全国', }) resolve(geocoder) } catch (error) { reject(error) } }) }) } export function geolocation() { return new Promise((resolve, reject) => { window.AMap.plugin('AMap.Geolocation', () => { const geolocation = new window.AMap.Geolocation({ // 是否使用高精度定位,默认:true enableHighAccuracy: true, // 设置定位超时时间,默认:无穷大 timeout: 10000, // 定位按钮的停靠位置的偏移量 offset: [10, 20], // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false zoomToAccuracy: true, // 定位按钮的排放位置, RB表示右下 position: 'RB', }) geolocation.getCurrentPosition((status, result) => { if (status === 'complete') { resolve(result) } else { reject(result) } }) }) }) } export default {}