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

fix(getLocation): ip定位取消坐标系转换 #4248

上级 d1edf51b
......@@ -42,7 +42,7 @@ export function getMapInfo () {
export const IS_AMAP = getMapInfo().type === MapType.AMAP
export function translateGeo (type, coords, skip) {
export function translateCoordinateSystem (type, coords, skip) {
const mapInfo = getMapInfo()
const wgs84Map = [MapType.GOOGLE]
if (
......@@ -77,10 +77,10 @@ export function translateGeo (type, coords, skip) {
speed: coords.speed
})
} else {
reject(new Error('translate geo fail'))
reject(new Error('translate coordinate system fail'))
}
},
() => reject(new Error('translate geo fail'))
() => reject(new Error('translate coordinate system fail'))
)
})
}
......@@ -104,7 +104,7 @@ export function translateGeo (type, coords, skip) {
speed: coords.speed
})
} else {
reject(new Error('translate geo fail'))
reject(new Error('translate coordinate system fail'))
}
}
)
......
......@@ -4,7 +4,7 @@ import {
import {
MapType,
getMapInfo,
translateGeo
translateCoordinateSystem
} from '../../../helpers/location'
import { loadMaps } from '../../../view/components/map/maps'
......@@ -26,7 +26,7 @@ export function getLocation ({
new Promise((resolve, reject) => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(res => resolve(res.coords), reject, {
navigator.geolocation.getCurrentPosition(res => resolve({ coords: res.coords }), reject, {
enableHighAccuracy: isHighAccuracy || altitude,
timeout: highAccuracyExpireTime || 1000 * 100
})
......@@ -42,9 +42,12 @@ export function getLocation ({
if ('result' in res && res.result.location) {
const location = res.result.location
resolve({
latitude: location.lat,
longitude: location.lng
}, true)
coords: {
latitude: location.lat,
longitude: location.lng
},
skip: true
})
} else {
reject(new Error(res.message || JSON.stringify(res)))
}
......@@ -57,9 +60,12 @@ export function getLocation ({
const data = res.data
if ('location' in data) {
resolve({
latitude: data.location.lat,
longitude: data.location.lng,
accuracy: data.accuracy
coords: {
latitude: data.location.lat,
longitude: data.location.lng,
accuracy: data.accuracy
},
skip: true
})
} else {
reject(new Error((data.error && data.error.message) || JSON.stringify(res)))
......@@ -80,9 +86,12 @@ export function getLocation ({
geolocation.getCurrentPosition((status, data) => {
if (status === 'complete') {
resolve({
latitude: data.position.lat,
longitude: data.position.lng,
accuracy: data.accuracy
coords: {
latitude: data.position.lat,
longitude: data.position.lng,
accuracy: data.accuracy
},
skip: true
})
} else {
reject(new Error(data.message))
......@@ -94,8 +103,8 @@ export function getLocation ({
reject(new Error('network error'))
}
})
}).then((coords, skip) => {
translateGeo(type, coords, skip)
}).then(({ coords, skip }) => {
translateCoordinateSystem(type, coords, skip)
.then(coords => {
invoke(
callbackId,
......
import { translateGeo } from '../../../helpers/location'
import { translateCoordinateSystem } from '../../../helpers/location'
const { invokeCallbackHandler: invoke } = UniServiceJSBridge
let successCallbackIds = []
......@@ -16,7 +16,7 @@ export function startLocationUpdate ({ type = 'gcj02' }, callbackId) {
watchId = watchId || navigator.geolocation.watchPosition(
res => {
started = true
translateGeo(type, res.coords)
translateCoordinateSystem(type, res.coords)
.then((coords) => {
successCallbackIds.forEach(callbackId => {
invoke(callbackId, coords)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册