提交 b87ad91d 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: H5高德地图增加坐标系转换并移除ip定位逻辑

上级 7841edf4
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
MapType, MapType,
getMapInfo getMapInfo
} from '../../../helpers/location' } from '../../../helpers/location'
import { loadMaps } from '../../../view/components/map/maps'
/** /**
* 获取定位信息 * 获取定位信息
...@@ -67,44 +68,57 @@ export function getLocation ({ ...@@ -67,44 +68,57 @@ export function getLocation ({
reject(new Error('network error')) reject(new Error('network error'))
} }
}) })
} else if (mapInfo.type === MapType.AMAP) {
window.AMap.plugin('AMap.Geolocation', function () {
var geolocation = new window.AMap.Geolocation({})
geolocation.getCurrentPosition(function (status, res) {
if (status === 'complete') {
resolve({
latitude: res.position.lat,
longitude: res.position.lng,
accuracy: res.accuracy
})
} else {
reject(new Error((res.message) || JSON.stringify(res)))
}
})
})
} else { } else {
reject(new Error('network error')) reject(new Error('network error'))
} }
}) })
}).then((coords, skip) => { }).then((coords, skip) => {
if (type.toUpperCase() === 'WGS84' || mapInfo.type !== MapType.QQ || skip) { const wgs84Map = [MapType.GOOGLE]
if (type.toUpperCase() === 'WGS84' || wgs84Map.includes(mapInfo.type) || skip) {
return coords return coords
} }
return new Promise((resolve, reject) => {
getJSONP(`https://apis.map.qq.com/jsapi?qt=translate&type=1&points=${coords.longitude},${coords.latitude}&key=${mapInfo.key}&output=jsonp&pf=jsapi&ref=jsapi`, { if (mapInfo.type === MapType.QQ) {
callback: 'cb' return new Promise((resolve) => {
}, (res) => { getJSONP(`https://apis.map.qq.com/jsapi?qt=translate&type=1&points=${coords.longitude},${coords.latitude}&key=${mapInfo.key}&output=jsonp&pf=jsapi&ref=jsapi`, {
if ('detail' in res && 'points' in res.detail && res.detail.points.length) { callback: 'cb'
const location = res.detail.points[0] }, (res) => {
resolve(Object.assign({}, coords, { if ('detail' in res && 'points' in res.detail && res.detail.points.length) {
longitude: location.lng, const location = res.detail.points[0]
latitude: location.lat resolve(Object.assign({}, coords, {
})) longitude: location.lng,
} else { latitude: location.lat
resolve(coords) }))
} } else {
}, () => resolve(coords)) resolve(coords)
}) }
}, () => resolve(coords))
})
}
if (mapInfo.type === MapType.AMAP) {
return new Promise((resolve) => {
loadMaps([], () => {
window.AMap.convertFrom(
[coords.longitude, coords.latitude],
'gps',
(_, res) => {
if (res.info === 'ok' && res.locations.length) {
const { lat, lng } = res.locations[0]
resolve(
Object.assign({}, coords, {
longitude: lng,
latitude: lat
})
)
} else {
resolve(coords)
}
}
)
})
})
}
}).then(coords => { }).then(coords => {
invoke(callbackId, Object.assign(coords, { invoke(callbackId, Object.assign(coords, {
errMsg: 'getLocation:ok', errMsg: 'getLocation:ok',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册