You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.6 KiB

import { ROOTPATH } from '@/common/config.js'
import store from '@/store'
// Reverse geocoding is proxied through our authenticated backend. The service key
// stays on the server, while saved coordinates and native maps remain GCJ-02.
export default class Tianditu {
reverseGeocoder(options) {
const { latitude, longitude } = options.location || {}
if (!Number.isFinite(Number(latitude)) || !Number.isFinite(Number(longitude)) ||
latitude == null || longitude == null || latitude === '' || longitude === '') {
const error = { message: '缺少有效定位坐标' }
if (options.fail) options.fail(error)
if (options.complete) options.complete(error)
return
}
const role = Number(store.state.vuex_my_role) === 1 ? 'nurse' : 'admin'
return uni.request({
url: `${ROOTPATH}/api/${role}/map/reverse-geocode`,
method: 'GET',
header: { Authorization: `Bearer ${store.state.vuex_token}` },
timeout: 12000,
data: { lng: longitude, lat: latitude, coordinate_type: 'gcj02' },
success: response => {
const data = response.data
if (response.statusCode === 200 && data && !data.errcode && data.result && data.result.address) {
if (options.success) options.success(data)
} else if (options.fail) {
options.fail({ message: data && data.errmsg || '天地图地址查询失败,请稍后重试' })
}
},
fail: error => { if (options.fail) options.fail(error) },
complete: response => { if (options.complete) options.complete(response) }
})
}
}