Wechat applet coordinate point to geographic location

1. Download SDK

I have already downloaded qqmap-wx-jssdk.min.js
in my resource, and I will attach the link after review

2. Write public methods

export const resetLonLat = async (str: string): Promise<string> => {
    
    
  if (!str) return ''
  const [longitude, latitude] = str.split(',')
  const QQMapWX = require('./qqmap-wx-jssdk.min.js')
  const qqmapsdk = new QQMapWX({
    
    
    key: '腾讯地图申请的key'
  });
  return new Promise((reslove, reject) => {
    
    
    qqmapsdk.reverseGeocoder({
    
    
      location: {
    
    
        longitude,
        latitude
      },
      success: (res: any) => {
    
    
        reslove(res.result.address)
      },
      fail: function (err: any) {
    
    
        reject(err)
      }
    })
  })
}

3. How to use

import {
    
     resetLonLat } from '@/utils/util'
// str  经纬度
const address = await resetLonLat(str) 

Guess you like

Origin blog.csdn.net/qq_45142260/article/details/129640875