增加腾讯地图根据地址获取座标的接口

This commit is contained in:
zhl 2021-04-21 15:43:25 +08:00
parent 6ad48ce196
commit d2cd8a909e
3 changed files with 40 additions and 5 deletions

View File

@ -1,12 +1,12 @@
import BaseController from '../../common/base.controller'
import { router } from '../../decorators/router'
import { queryArea } from '../../services/TencentMap'
import { addressToLoc, queryArea } from '../../services/TencentMap'
import { ZError } from '../../common/ZError'
class MapController extends BaseController {
@router('post /area/query')
async fetchArea(req, res) {
let {keyword, region} = req.params
let { keyword, region } = req.params
let data = await queryArea(keyword, region)
if (data.status != 0) {
throw new ZError(data.status, data.message)
@ -16,4 +16,14 @@ class MapController extends BaseController {
records: data.data
}
}
@router('post /area/geocoder')
async areaToLoc(req, res) {
let { address } = req.params
let data = await addressToLoc(address)
if (data.status != 0) {
throw new ZError(data.status, data.message)
}
return data.result
}
}

View File

@ -6,7 +6,7 @@ import {
getModelForClass,
index,
modelOptions,
plugin, prop
plugin, post, prop
} from '@typegoose/typegoose'
import { dbconn } from '../../decorators/dbconn'
import { checkJson, noJson } from '../../decorators/nojson'
@ -20,6 +20,12 @@ const saveExcludeKeys = ['createdAt', 'updatedAt', '__v', '_id']
class ShopClass extends FindOrCreate {
@prop({ required: true })
public name!: string
/**
*
* @type {string}
*/
@prop()
public showName: string
/**
*
* @type {string}
@ -77,6 +83,14 @@ class ShopClass extends FindOrCreate {
@prop({default: true})
public show: boolean
@prop()
public logo: string
@prop()
public category: string
@prop()
public extData: string
public updateFromReq(data: any) {
for (let key in data) {

View File

@ -3,10 +3,9 @@ import { md5 } from '../utils/security.util'
const key = 'SWKBZ-SI6C3-TNG3L-3IXSD-XLLXV-CJB5Q'
const signKey = 'EuadDaRCGIyXpxEMSCJqPS2t4NGA44Rt'
const host = 'https://apis.map.qq.com'
export async function queryArea(keyword: string, region: string) {
let host = 'https://apis.map.qq.com'
let path = '/ws/place/v1/suggestion'
let signStr = `${path}?key=${key}&keyword=${keyword}&region=${region}${signKey}`
let sig = md5(signStr)
@ -22,3 +21,15 @@ export async function queryArea(keyword: string, region: string) {
return res.data
})
}
export async function addressToLoc(address: string) {
let path = '/ws/geocoder/v1/'
let signStr = `${path}?address=${address}&key=${key}${signKey}`
let sig = md5(signStr)
let data = {address, key, sig}
let url = `${host}${path}`
return axios.get(url, {params: data})
.then(res => {
return res.data
})
}