let cacheLocation = {
  latitude: 0,
  longitude: 0
}

export function fetchLocation() {
  return new Promise(resolve => {
    uni.getLocation({
      type: 'gcj02',
      success: res => {
        const latitude = res.latitude
        const longitude = res.longitude
        cacheLocation = {
          latitude,
          longitude
        }
        getApp<any>().globalData.fetchLocation = cacheLocation
        resolve(cacheLocation)
      },
      fail: err => {
        // console.log(err)
        if (/auth/.test(err.errMsg)) {
          resolve({
            latitude: 23.098994,
            longitude: 113.32252
          })
          return
        }
        if (/电量/.test(err.errMsg)) {
          resolve(cacheLocation)
          return
        }
        uni.showModal({
          content: `${err.errMsg},请重试`
        })
      }
    })
  })
}
