@shencom/api
Version:
shencom api group
185 lines (158 loc) • 4.68 kB
text/typescript
import type { Unfurl } from '@shencom/typing';
import { getInitializedApiConfig } from '../config';
const url = 'https://apis.map.qq.com/ws';
export interface QQMapResultRoot<T> {
message: string;
request_id: string;
result: T;
status: number;
}
interface Location {
lat: number;
lng: number;
}
interface Addresscomponent {
nation: string;
province: string;
city: string;
district: string;
street: string;
street_number: string;
}
type ResQQMapGeocodeGeo = QQMapResultRoot<GeocodeGeoResult>;
interface ReqQQMapGeocodeGeo {
key: string;
/** 规则遵循:国家、省份、城市、区县、城镇、乡村、街道、门牌号码、屋邨、大厦,如:北京市朝阳区阜通东大街6号。 */
address: string;
}
export interface GeocodeGeoResult {
title: string;
location: Location;
ad_info: GeocodeGeoAdinfo;
address_components: Addresscomponent;
similarity: number;
deviation: number;
reliability: number;
level: number;
}
interface GeocodeGeoAdinfo {
adcode: string;
}
/**
* 官方接口说明: https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
* @summary 腾讯-逆地址解析
* @param key
* @param location 经纬度(GCJ02坐标系),格式: location=lat<纬度>,lng<经度>
* @param getPoi 是否返回周边地点(POI)列表,可选值: 0 不返回(默认) 1 返回
*/
export const ApiQQMapGeocodeGeo = (
body: Unfurl<ReqQQMapGeocodeGeo>,
headers?: Record<string, any>,
) => {
const { http } = getInitializedApiConfig();
const api = `${url}/geocoder/v1`;
return http.get<ResQQMapGeocodeGeo, ReqQQMapGeocodeGeo, true>(api, body, {
headers: { Authorization: null, ...headers },
});
};
type ReqQQMapGeocodeRegeo = Unfurl<{
key: string;
/** 经纬度(GCJ02坐标系),格式:location=lat<纬度>,lng<经度> */
location: string;
/** 是否返回周边地点(POI)列表,可选值:
0 不返回(默认)
1 返回
*/
get_poi?: 0 | 1;
/** 周边POI列表控制
* 参考官网
*/
poi_options?: number;
}>;
type ResQQMapGeocodeRegeo = QQMapResultRoot<GeocodeRegeoResult>;
export interface GeocodeRegeoResult {
location: Location;
address: string;
formatted_addresses: GeocodeRegeoFormattedaddresses;
address_component: Addresscomponent;
ad_info: GeocodeRegeoAdinfo;
address_reference: GeocodeRegeoAddressReference;
}
interface GeocodeRegeoAddressReference {
business_area: GeocodeRegeoBusinessarea;
famous_area: GeocodeRegeoBusinessarea;
crossroad: GeocodeRegeoBusinessarea;
town: GeocodeRegeoBusinessarea;
street_number: GeocodeRegeoBusinessarea;
street: GeocodeRegeoBusinessarea;
landmark_l2: GeocodeRegeoBusinessarea;
}
interface GeocodeRegeoBusinessarea {
id: string;
title: string;
location: Location;
_distance: number;
_dir_desc: string;
}
interface GeocodeRegeoAdinfo {
nation_code: string;
adcode: string;
city_code: string;
name: string;
location: Location;
nation: string;
province: string;
city: string;
district: string;
}
interface GeocodeRegeoFormattedaddresses {
recommend: string;
rough: string;
}
/**
* 官方接口说明: https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
* @summary 腾讯-逆地址解析
* @param key
* @param location 经纬度(GCJ02坐标系),格式: location=lat<纬度>,lng<经度>
* @param getPoi 是否返回周边地点(POI)列表,可选值: 0 不返回(默认) 1 返回
*/
export const ApiQQMapGeocodeRegeo = (
body: Unfurl<ReqQQMapGeocodeRegeo>,
headers?: Record<string, any>,
) => {
const api = `${url}/geocoder/v1`;
const { http } = getInitializedApiConfig();
return http.get<ResQQMapGeocodeRegeo, ReqQQMapGeocodeRegeo, true>(api, body, {
headers: { Authorization: null, ...headers },
});
};
type ReqQQMapIP = Unfurl<{
key: string;
ip?: string;
}>;
type ResQQMapIP = QQMapResultRoot<IPResult>;
export interface IPResult {
ad_info: IPAdInfo;
ip: string;
location: Location;
}
interface IPAdInfo {
adcode: number;
city: string;
district: string;
nation: string;
province: string;
}
/**
* 官方接口说明: https://lbs.qq.com/service/webService/webServiceGuide/webServiceIp
* @summary 腾讯-IP定位
* @param key
* @param ip IP地址,缺省时会使用请求端的IP
*/
export const ApiQQMapIP = (body: Unfurl<ReqQQMapIP>, headers?: Record<string, any>) => {
const api = `${url}/location/v1/ip`;
const { http } = getInitializedApiConfig();
return http.get<ResQQMapIP, ReqQQMapIP, true>(api, body, {
headers: { Authorization: null, ...headers },
});
};