import { fetch, apis } from '@/utils/request'

export function regeo(key, params) {
  return new Promise((resolve, reject) => {
    fetch(apis.amap.regeo)({
      params: {
        key,
        output: 'json',
        extensions: 'base',
        batch: 'false',
        roadlevel: 0,
        ...params,
      }
    }).then(res => {
      if (res.status === '1' && res.infocode === '10000') {
        resolve(res.regeocode)
      } else {
        console.error(res)
        resolve(res.info)
      }
    }).catch(err => {
      console.error(err)
      resolve(err.message)
    })
  })
}
