123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- export function geolocation() {
- return new Promise((resolve, reject) => {
- window.AMap.plugin('AMap.Geolocation', () => {
- const geolocation = new window.AMap.Geolocation({
- // 是否使用高精度定位,默认:true
- enableHighAccuracy: true,
- // 设置定位超时时间,默认:无穷大
- timeout: 10000,
- })
- geolocation.getCurrentPosition((status, result) => {
- if (status === 'complete') {
- resolve(result)
- } else {
- reject(result)
- }
- })
- })
- })
- }
- // 高德转百度坐标
- export function convertor(lng, lat) {
- return new Promise((resolve, reject) => {
- const convertor = new window.BMapGL.Convertor()
- // 高德转百度
- convertor.translate([new window.BMapGL.Point(lng, lat)], 3, 5, (data) => {
- if (data.status === 0) {
- resolve(data.points[0])
- } else {
- reject()
- }
- })
- })
- }
- // 地址导航
- export async function mapNavigate(options = {}, origin) {
- console.log(options)
- // 百度
- if (origin === 'baidu') {
- const point = await convertor(options.lng, options.lat)
- console.log(point)
- console.log('百度地图')
- options.locationUrl = `http://api.map.baidu.com/marker?location=${point.lat},${point.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`
- }
- // return
- // window.open(options.locationUrl)
- window.location.href = options.locationUrl
- }
|