function mapInit(callback) { function loadScript() { var script = document.createElement('script') script.src = 'https://api.map.baidu.com/api?v=1.0&type=webgl&ak=vsIfSztpPmCtmBRfRiIAM57hbxBQbmgQ&callback=initMapApi' document.body.appendChild(script) } if (!window.BMapGL) { window.initMapApi = callback loadScript() } else { callback() } } // 定位当前位置 export function loactionSelf() { return new Promise((resolve, reject) => { mapInit(() => { const BMapGL = window.BMapGL var geolocation = new BMapGL.Geolocation({ // 是否使用高精度定位,默认:true enableHighAccuracy: true, // 设置定位超时时间,默认:无穷大 timeout: 10000, }) // 开启SDK辅助定位 geolocation.enableSDKLocation() geolocation.getCurrentPosition(function (r) { // alert(JSON.stringify(r)) if (this.getStatus() === 0) { // alert(JSON.stringify(r)) resolve({ point: r.point, address: r.address, }) } else { reject('failed' + this.getStatus()) } }) }) }) } // 地址导航 export function mapNavigate(options = {}, origin) { console.log(options) // 百度 if (origin === 'baidu') { console.log('百度地图') options.locationUrl = `http://api.map.baidu.com/marker?location=${options.lat},${options.lng}&title=${options.title}&content=${options.address}&output=html&src=webapp.baidu.openAPIdemo` } // 腾讯 if (origin === 'tx') { console.log('腾讯地图') options.locationUrl = `https://apis.map.qq.com/uri/v1/marker?marker=coord:${options.lat},${options.lng};${options.title};addr:${options.address}&referer=BWUBZ-LRLCQ-JON5T-GJLC4-URIMQ-CRBO6` } // 高德 if (origin === 'gaode') { console.log('高德地图') options.locationUrl = `https://uri.amap.com/marker?position=${options.lng},${options.lat}&name=${options.title}&coordinate=gaode&callnative=0` } // window.open(options.locationUrl) window.location.href = options.locationUrl }