Browse Source

尝试获取精确地址

dev
巴林闲侠 2 years ago
parent
commit
4c0c0bb546
  1. 5
      weapp/src/packages/patrol/index.jsx

5
weapp/src/packages/patrol/index.jsx

@ -157,16 +157,19 @@ const Index = () => {
Taro.showLoading({ title: '加载中' }) Taro.showLoading({ title: '加载中' })
let key = 'ODQBZ-3FZAU-6VIVL-2XXNM-F7CP7-WVFCY' // key let key = 'ODQBZ-3FZAU-6VIVL-2XXNM-F7CP7-WVFCY' // key
Taro.getLocation({ Taro.getLocation({
type: 'wgs84', // type: 'wgs84',
type: 'gcj02',
isHighAccuracy: true, isHighAccuracy: true,
highAccuracyExpireTime: 1000 * 6, highAccuracyExpireTime: 1000 * 6,
success: function (res) { success: function (res) {
console.log(res);
setLongitude(res.longitude) setLongitude(res.longitude)
setLatitude(res.latitude) setLatitude(res.latitude)
Taro.request({ Taro.request({
url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=${key}`, url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=${key}`,
success: function (res) { success: function (res) {
// res // res
console.log('地址信息:', res);
let addresscity = '' let addresscity = ''
addresscity = addresscity =
res.data.result.address_component.province res.data.result.address_component.province

Loading…
Cancel
Save