expo-gaode-map-web-api 1.0.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +632 -0
- package/build/index.d.ts +91 -0
- package/build/index.js +186 -0
- package/build/services/GeocodeService.d.ts +97 -0
- package/build/services/GeocodeService.js +133 -0
- package/build/services/InputTipsService.d.ts +103 -0
- package/build/services/InputTipsService.js +127 -0
- package/build/services/POIService.d.ts +133 -0
- package/build/services/POIService.js +174 -0
- package/build/services/RouteService.d.ts +149 -0
- package/build/services/RouteService.js +203 -0
- package/build/types/geocode.types.d.ts +326 -0
- package/build/types/geocode.types.js +5 -0
- package/build/types/inputtips.types.d.ts +69 -0
- package/build/types/inputtips.types.js +6 -0
- package/build/types/poi.types.d.ts +319 -0
- package/build/types/poi.types.js +7 -0
- package/build/types/route.types.d.ts +636 -0
- package/build/types/route.types.js +71 -0
- package/build/utils/client.d.ts +78 -0
- package/build/utils/client.js +144 -0
- package/build/utils/errorCodes.d.ts +35 -0
- package/build/utils/errorCodes.js +396 -0
- package/package.json +39 -0
- package/package.json.backup +40 -0
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 高德地图 Web API 模块
|
|
3
|
+
*
|
|
4
|
+
* 提供基于高德地图 Web API 的各种服务,包括:
|
|
5
|
+
* - 地理编码/逆地理编码
|
|
6
|
+
* - 路径规划(驾车、步行、骑行、电动车、公交)
|
|
7
|
+
* - POI 搜索(关键字搜索、周边搜索、多边形搜索)
|
|
8
|
+
* - 输入提示(搜索建议)
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { GaodeWebAPI } from 'expo-gaode-map-web-api';
|
|
14
|
+
*
|
|
15
|
+
* // 创建实例
|
|
16
|
+
* const api = new GaodeWebAPI();
|
|
17
|
+
*
|
|
18
|
+
* // 逆地理编码
|
|
19
|
+
* const result = await api.geocode.regeocode('116.481028,39.989643');
|
|
20
|
+
* console.log(result.regeocode.formatted_address);
|
|
21
|
+
*
|
|
22
|
+
* // 地理编码
|
|
23
|
+
* const result = await api.geocode.geocode('北京市朝阳区阜通东大街6号');
|
|
24
|
+
* console.log(result.geocodes[0].location);
|
|
25
|
+
*
|
|
26
|
+
* // 驾车路径规划
|
|
27
|
+
* const route = await api.route.driving('116.481028,39.989643', '116.434446,39.90816');
|
|
28
|
+
* console.log(`距离:${route.route.paths[0].distance}米`);
|
|
29
|
+
*
|
|
30
|
+
* // POI 搜索
|
|
31
|
+
* const pois = await api.poi.search('肯德基', { city: '北京' });
|
|
32
|
+
* console.log(`找到 ${pois.count} 个结果`);
|
|
33
|
+
*
|
|
34
|
+
* // 输入提示
|
|
35
|
+
* const tips = await api.inputTips.getTips('肯德基', { city: '北京' });
|
|
36
|
+
* console.log(`找到 ${tips.count} 个建议`);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
import { ClientConfig } from './utils/client';
|
|
40
|
+
import { GeocodeService } from './services/GeocodeService';
|
|
41
|
+
import { RouteService } from './services/RouteService';
|
|
42
|
+
import { POIService } from './services/POIService';
|
|
43
|
+
import { InputTipsService } from './services/InputTipsService';
|
|
44
|
+
export * from './types/geocode.types';
|
|
45
|
+
export * from './types/route.types';
|
|
46
|
+
export * from './types/inputtips.types';
|
|
47
|
+
export type { POISearchParams, POIAroundParams, POIPolygonParams, POIDetailParams, POIInfo, POISearchResponse, } from './types/poi.types';
|
|
48
|
+
export type { ClientConfig, APIError } from './utils/client';
|
|
49
|
+
export { GaodeAPIError } from './utils/client';
|
|
50
|
+
export { getErrorInfo, isSuccess, ERROR_CODE_MAP } from './utils/errorCodes';
|
|
51
|
+
export type { InfoCode, ErrorInfo } from './utils/errorCodes';
|
|
52
|
+
/**
|
|
53
|
+
* 高德地图 Web API 主类
|
|
54
|
+
*/
|
|
55
|
+
export declare class GaodeWebAPI {
|
|
56
|
+
private client;
|
|
57
|
+
/** 地理编码服务 */
|
|
58
|
+
geocode: GeocodeService;
|
|
59
|
+
/** 路径规划服务 */
|
|
60
|
+
route: RouteService;
|
|
61
|
+
/** POI 搜索服务 */
|
|
62
|
+
poi: POIService;
|
|
63
|
+
/** 输入提示服务 */
|
|
64
|
+
inputTips: InputTipsService;
|
|
65
|
+
/**
|
|
66
|
+
* 创建高德地图 Web API 实例
|
|
67
|
+
*
|
|
68
|
+
* @param config 配置选项(可选)
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const api = new GaodeWebAPI({
|
|
73
|
+
* key: 'your-web-api-key',
|
|
74
|
+
* timeout: 10000
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
constructor(config?: ClientConfig);
|
|
79
|
+
/**
|
|
80
|
+
* 更新 API Key
|
|
81
|
+
*/
|
|
82
|
+
setKey(key: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* 获取当前 API Key
|
|
85
|
+
*/
|
|
86
|
+
getKey(): string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 创建默认导出,方便使用
|
|
90
|
+
*/
|
|
91
|
+
export default GaodeWebAPI;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 高德地图 Web API 模块
|
|
4
|
+
*
|
|
5
|
+
* 提供基于高德地图 Web API 的各种服务,包括:
|
|
6
|
+
* - 地理编码/逆地理编码
|
|
7
|
+
* - 路径规划(驾车、步行、骑行、电动车、公交)
|
|
8
|
+
* - POI 搜索(关键字搜索、周边搜索、多边形搜索)
|
|
9
|
+
* - 输入提示(搜索建议)
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { GaodeWebAPI } from 'expo-gaode-map-web-api';
|
|
15
|
+
*
|
|
16
|
+
* // 创建实例
|
|
17
|
+
* const api = new GaodeWebAPI();
|
|
18
|
+
*
|
|
19
|
+
* // 逆地理编码
|
|
20
|
+
* const result = await api.geocode.regeocode('116.481028,39.989643');
|
|
21
|
+
* console.log(result.regeocode.formatted_address);
|
|
22
|
+
*
|
|
23
|
+
* // 地理编码
|
|
24
|
+
* const result = await api.geocode.geocode('北京市朝阳区阜通东大街6号');
|
|
25
|
+
* console.log(result.geocodes[0].location);
|
|
26
|
+
*
|
|
27
|
+
* // 驾车路径规划
|
|
28
|
+
* const route = await api.route.driving('116.481028,39.989643', '116.434446,39.90816');
|
|
29
|
+
* console.log(`距离:${route.route.paths[0].distance}米`);
|
|
30
|
+
*
|
|
31
|
+
* // POI 搜索
|
|
32
|
+
* const pois = await api.poi.search('肯德基', { city: '北京' });
|
|
33
|
+
* console.log(`找到 ${pois.count} 个结果`);
|
|
34
|
+
*
|
|
35
|
+
* // 输入提示
|
|
36
|
+
* const tips = await api.inputTips.getTips('肯德基', { city: '北京' });
|
|
37
|
+
* console.log(`找到 ${tips.count} 个建议`);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
41
|
+
if (k2 === undefined) k2 = k;
|
|
42
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
43
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
44
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
45
|
+
}
|
|
46
|
+
Object.defineProperty(o, k2, desc);
|
|
47
|
+
}) : (function(o, m, k, k2) {
|
|
48
|
+
if (k2 === undefined) k2 = k;
|
|
49
|
+
o[k2] = m[k];
|
|
50
|
+
}));
|
|
51
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
52
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
53
|
+
};
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.GaodeWebAPI = exports.ERROR_CODE_MAP = exports.isSuccess = exports.getErrorInfo = exports.GaodeAPIError = void 0;
|
|
56
|
+
/**
|
|
57
|
+
* 在加载 Web API 模块前,强制校验“基础地图提供者”是否已安装。
|
|
58
|
+
* 支持以下任一包:
|
|
59
|
+
* - expo-gaode-map(核心地图包)
|
|
60
|
+
* - expo-gaode-map-navigation(导航包,内置地图能力)
|
|
61
|
+
* 这样可避免导航与核心包 SDK 冲突时无法使用的问题。
|
|
62
|
+
*/
|
|
63
|
+
function ensureBaseInstalled() {
|
|
64
|
+
let installed = false;
|
|
65
|
+
try {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
67
|
+
require('expo-gaode-map');
|
|
68
|
+
installed = true;
|
|
69
|
+
}
|
|
70
|
+
catch (_) {
|
|
71
|
+
try {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
73
|
+
require('expo-gaode-map-navigation');
|
|
74
|
+
installed = true;
|
|
75
|
+
}
|
|
76
|
+
catch (_) {
|
|
77
|
+
installed = false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!installed) {
|
|
81
|
+
const msg = '[expo-gaode-map-web-api] 需要先安装基础地图组件,支持以下任一包:\n' +
|
|
82
|
+
' - expo-gaode-map(核心地图包),或\n' +
|
|
83
|
+
' - expo-gaode-map-navigation(导航包,内置地图能力)\n' +
|
|
84
|
+
'请先安装并完成原生配置后再重试。';
|
|
85
|
+
throw new Error(msg);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
ensureBaseInstalled();
|
|
89
|
+
const client_1 = require("./utils/client");
|
|
90
|
+
const GeocodeService_1 = require("./services/GeocodeService");
|
|
91
|
+
const RouteService_1 = require("./services/RouteService");
|
|
92
|
+
const POIService_1 = require("./services/POIService");
|
|
93
|
+
const InputTipsService_1 = require("./services/InputTipsService");
|
|
94
|
+
/**
|
|
95
|
+
* 从核心包解析 getWebKey(运行时解析,避免类型导出时序问题)
|
|
96
|
+
*/
|
|
97
|
+
function resolveWebKey() {
|
|
98
|
+
// 1) 尝试从核心地图包读取
|
|
99
|
+
try {
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
101
|
+
const core = require('expo-gaode-map');
|
|
102
|
+
const fn = core?.getWebKey;
|
|
103
|
+
if (typeof fn === 'function') {
|
|
104
|
+
return fn();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// ignore
|
|
109
|
+
}
|
|
110
|
+
// 2) 若未安装核心包,则尝试从导航包读取(导航内置地图)
|
|
111
|
+
try {
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
113
|
+
const nav = require('expo-gaode-map-navigation');
|
|
114
|
+
const fn2 = nav?.getWebKey;
|
|
115
|
+
if (typeof fn2 === 'function') {
|
|
116
|
+
return fn2();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
// ignore
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
// 导出类型
|
|
125
|
+
__exportStar(require("./types/geocode.types"), exports);
|
|
126
|
+
__exportStar(require("./types/route.types"), exports);
|
|
127
|
+
__exportStar(require("./types/inputtips.types"), exports);
|
|
128
|
+
var client_2 = require("./utils/client");
|
|
129
|
+
Object.defineProperty(exports, "GaodeAPIError", { enumerable: true, get: function () { return client_2.GaodeAPIError; } });
|
|
130
|
+
// 错误码相关导出
|
|
131
|
+
var errorCodes_1 = require("./utils/errorCodes");
|
|
132
|
+
Object.defineProperty(exports, "getErrorInfo", { enumerable: true, get: function () { return errorCodes_1.getErrorInfo; } });
|
|
133
|
+
Object.defineProperty(exports, "isSuccess", { enumerable: true, get: function () { return errorCodes_1.isSuccess; } });
|
|
134
|
+
Object.defineProperty(exports, "ERROR_CODE_MAP", { enumerable: true, get: function () { return errorCodes_1.ERROR_CODE_MAP; } });
|
|
135
|
+
/**
|
|
136
|
+
* 高德地图 Web API 主类
|
|
137
|
+
*/
|
|
138
|
+
class GaodeWebAPI {
|
|
139
|
+
/**
|
|
140
|
+
* 创建高德地图 Web API 实例
|
|
141
|
+
*
|
|
142
|
+
* @param config 配置选项(可选)
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const api = new GaodeWebAPI({
|
|
147
|
+
* key: 'your-web-api-key',
|
|
148
|
+
* timeout: 10000
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
constructor(config = {}) {
|
|
153
|
+
const webKey = resolveWebKey();
|
|
154
|
+
if (!webKey) {
|
|
155
|
+
throw new Error('[expo-gaode-map-web-api] 必须先通过 ExpoGaodeMapModule.initSDK({ webKey }) 初始化并提供 Web API Key。\n' +
|
|
156
|
+
'请在应用启动时调用:\n' +
|
|
157
|
+
" import { ExpoGaodeMapModule } from 'expo-gaode-map';\n" +
|
|
158
|
+
' ExpoGaodeMapModule.initSDK({ webKey: \"your-web-api-key\", iosKey, androidKey });\n' +
|
|
159
|
+
'随后再创建 GaodeWebAPI 实例使用 Web API 能力。');
|
|
160
|
+
}
|
|
161
|
+
// 强制使用核心模块中的 webKey,避免直接在此处绕过初始化约束
|
|
162
|
+
const effectiveConfig = { ...config, key: webKey };
|
|
163
|
+
this.client = new client_1.GaodeWebAPIClient(effectiveConfig);
|
|
164
|
+
this.geocode = new GeocodeService_1.GeocodeService(this.client);
|
|
165
|
+
this.route = new RouteService_1.RouteService(this.client);
|
|
166
|
+
this.poi = new POIService_1.POIService(this.client);
|
|
167
|
+
this.inputTips = new InputTipsService_1.InputTipsService(this.client);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 更新 API Key
|
|
171
|
+
*/
|
|
172
|
+
setKey(key) {
|
|
173
|
+
this.client.setKey(key);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 获取当前 API Key
|
|
177
|
+
*/
|
|
178
|
+
getKey() {
|
|
179
|
+
return this.client.getKey();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.GaodeWebAPI = GaodeWebAPI;
|
|
183
|
+
/**
|
|
184
|
+
* 创建默认导出,方便使用
|
|
185
|
+
*/
|
|
186
|
+
exports.default = GaodeWebAPI;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 高德地图 Web API - 地理编码服务
|
|
3
|
+
*/
|
|
4
|
+
import { GaodeWebAPIClient } from '../utils/client';
|
|
5
|
+
import type { RegeocodeParams, RegeocodeResponse, GeocodeResponse } from '../types/geocode.types';
|
|
6
|
+
/**
|
|
7
|
+
* 地理编码服务
|
|
8
|
+
*/
|
|
9
|
+
export declare class GeocodeService {
|
|
10
|
+
private client;
|
|
11
|
+
constructor(client: GaodeWebAPIClient);
|
|
12
|
+
/**
|
|
13
|
+
* 逆地理编码
|
|
14
|
+
* 将经纬度坐标转换为地址信息
|
|
15
|
+
*
|
|
16
|
+
* @param location 经纬度坐标,格式:经度,纬度 或 { longitude, latitude }
|
|
17
|
+
* @param options 可选参数
|
|
18
|
+
* @returns 地址信息
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // 方式1:使用字符串
|
|
23
|
+
* const result = await geocode.regeocode('116.481028,39.989643');
|
|
24
|
+
*
|
|
25
|
+
* // 方式2:使用对象
|
|
26
|
+
* const result = await geocode.regeocode({
|
|
27
|
+
* longitude: 116.481028,
|
|
28
|
+
* latitude: 39.989643
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // 方式3:带可选参数
|
|
32
|
+
* const result = await geocode.regeocode('116.481028,39.989643', {
|
|
33
|
+
* extensions: 'all',
|
|
34
|
+
* radius: 1000
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* console.log(result.regeocode.formatted_address);
|
|
38
|
+
* // 输出:北京市朝阳区阜通东大街6号
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
regeocode(location: string | {
|
|
42
|
+
longitude: number;
|
|
43
|
+
latitude: number;
|
|
44
|
+
}, options?: Omit<RegeocodeParams, 'location'>): Promise<RegeocodeResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* 地理编码
|
|
47
|
+
* 将地址转换为经纬度坐标
|
|
48
|
+
*
|
|
49
|
+
* @param address 地址
|
|
50
|
+
* @param city 可选,指定查询的城市
|
|
51
|
+
* @returns 坐标信息
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // 基础用法
|
|
56
|
+
* const result = await geocode.geocode('北京市朝阳区阜通东大街6号');
|
|
57
|
+
* console.log(result.geocodes[0].location);
|
|
58
|
+
* // 输出:116.481028,39.989643
|
|
59
|
+
*
|
|
60
|
+
* // 指定城市
|
|
61
|
+
* const result = await geocode.geocode('阜通东大街6号', '北京');
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
geocode(address: string, city?: string): Promise<GeocodeResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* 批量逆地理编码
|
|
67
|
+
*
|
|
68
|
+
* @param locations 坐标列表
|
|
69
|
+
* @param options 可选参数
|
|
70
|
+
* @returns 地址信息列表
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const result = await geocode.batchRegeocode([
|
|
75
|
+
* '116.481028,39.989643',
|
|
76
|
+
* '116.434446,39.90816'
|
|
77
|
+
* ]);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
batchRegeocode(locations: string[], options?: Omit<RegeocodeParams, 'location' | 'batch'>): Promise<RegeocodeResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* 批量地理编码
|
|
83
|
+
*
|
|
84
|
+
* @param addresses 地址列表
|
|
85
|
+
* @param city 可选,指定查询的城市
|
|
86
|
+
* @returns 坐标信息列表
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const result = await geocode.batchGeocode([
|
|
91
|
+
* '北京市朝阳区阜通东大街6号',
|
|
92
|
+
* '北京市朝阳区望京SOHO'
|
|
93
|
+
* ], '北京');
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
batchGeocode(addresses: string[], city?: string): Promise<GeocodeResponse>;
|
|
97
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 高德地图 Web API - 地理编码服务
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GeocodeService = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* 地理编码服务
|
|
9
|
+
*/
|
|
10
|
+
class GeocodeService {
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 逆地理编码
|
|
16
|
+
* 将经纬度坐标转换为地址信息
|
|
17
|
+
*
|
|
18
|
+
* @param location 经纬度坐标,格式:经度,纬度 或 { longitude, latitude }
|
|
19
|
+
* @param options 可选参数
|
|
20
|
+
* @returns 地址信息
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // 方式1:使用字符串
|
|
25
|
+
* const result = await geocode.regeocode('116.481028,39.989643');
|
|
26
|
+
*
|
|
27
|
+
* // 方式2:使用对象
|
|
28
|
+
* const result = await geocode.regeocode({
|
|
29
|
+
* longitude: 116.481028,
|
|
30
|
+
* latitude: 39.989643
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // 方式3:带可选参数
|
|
34
|
+
* const result = await geocode.regeocode('116.481028,39.989643', {
|
|
35
|
+
* extensions: 'all',
|
|
36
|
+
* radius: 1000
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* console.log(result.regeocode.formatted_address);
|
|
40
|
+
* // 输出:北京市朝阳区阜通东大街6号
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
async regeocode(location, options) {
|
|
44
|
+
// 处理坐标参数
|
|
45
|
+
let locationStr;
|
|
46
|
+
if (typeof location === 'string') {
|
|
47
|
+
locationStr = location;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
locationStr = `${location.longitude},${location.latitude}`;
|
|
51
|
+
}
|
|
52
|
+
// 构建请求参数
|
|
53
|
+
const params = {
|
|
54
|
+
location: locationStr,
|
|
55
|
+
...options,
|
|
56
|
+
};
|
|
57
|
+
// 发起请求
|
|
58
|
+
return this.client.request('/v3/geocode/regeo', params);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 地理编码
|
|
62
|
+
* 将地址转换为经纬度坐标
|
|
63
|
+
*
|
|
64
|
+
* @param address 地址
|
|
65
|
+
* @param city 可选,指定查询的城市
|
|
66
|
+
* @returns 坐标信息
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // 基础用法
|
|
71
|
+
* const result = await geocode.geocode('北京市朝阳区阜通东大街6号');
|
|
72
|
+
* console.log(result.geocodes[0].location);
|
|
73
|
+
* // 输出:116.481028,39.989643
|
|
74
|
+
*
|
|
75
|
+
* // 指定城市
|
|
76
|
+
* const result = await geocode.geocode('阜通东大街6号', '北京');
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
async geocode(address, city) {
|
|
80
|
+
const params = {
|
|
81
|
+
address,
|
|
82
|
+
city,
|
|
83
|
+
};
|
|
84
|
+
return this.client.request('/v3/geocode/geo', params);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 批量逆地理编码
|
|
88
|
+
*
|
|
89
|
+
* @param locations 坐标列表
|
|
90
|
+
* @param options 可选参数
|
|
91
|
+
* @returns 地址信息列表
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const result = await geocode.batchRegeocode([
|
|
96
|
+
* '116.481028,39.989643',
|
|
97
|
+
* '116.434446,39.90816'
|
|
98
|
+
* ]);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
async batchRegeocode(locations, options) {
|
|
102
|
+
const params = {
|
|
103
|
+
location: locations.join('|'),
|
|
104
|
+
batch: true,
|
|
105
|
+
...options,
|
|
106
|
+
};
|
|
107
|
+
return this.client.request('/v3/geocode/regeo', params);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 批量地理编码
|
|
111
|
+
*
|
|
112
|
+
* @param addresses 地址列表
|
|
113
|
+
* @param city 可选,指定查询的城市
|
|
114
|
+
* @returns 坐标信息列表
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const result = await geocode.batchGeocode([
|
|
119
|
+
* '北京市朝阳区阜通东大街6号',
|
|
120
|
+
* '北京市朝阳区望京SOHO'
|
|
121
|
+
* ], '北京');
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
async batchGeocode(addresses, city) {
|
|
125
|
+
const params = {
|
|
126
|
+
address: addresses.join('|'),
|
|
127
|
+
batch: true,
|
|
128
|
+
city,
|
|
129
|
+
};
|
|
130
|
+
return this.client.request('/v3/geocode/geo', params);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.GeocodeService = GeocodeService;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 高德地图 Web API - 输入提示服务
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { GaodeWebAPIClient } from '../utils/client';
|
|
6
|
+
import type { InputTipsParams, InputTipsResponse } from '../types/inputtips.types';
|
|
7
|
+
/**
|
|
8
|
+
* 输入提示服务
|
|
9
|
+
* 提供根据用户输入的关键词查询返回建议列表
|
|
10
|
+
*/
|
|
11
|
+
export declare class InputTipsService {
|
|
12
|
+
private client;
|
|
13
|
+
constructor(client: GaodeWebAPIClient);
|
|
14
|
+
/**
|
|
15
|
+
* 获取输入提示
|
|
16
|
+
* 根据用户输入的关键词返回建议列表
|
|
17
|
+
*
|
|
18
|
+
* @param keywords 查询关键词
|
|
19
|
+
* @param options 可选参数
|
|
20
|
+
* @returns 输入提示结果
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // 基础搜索
|
|
25
|
+
* const result = await inputTips.getTips('肯德基');
|
|
26
|
+
*
|
|
27
|
+
* // 指定城市搜索
|
|
28
|
+
* const result = await inputTips.getTips('肯德基', {
|
|
29
|
+
* city: '北京',
|
|
30
|
+
* citylimit: true
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // 指定位置和类型
|
|
34
|
+
* const result = await inputTips.getTips('银行', {
|
|
35
|
+
* location: '116.481488,39.990464',
|
|
36
|
+
* type: '150100',
|
|
37
|
+
* city: '010'
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // 搜索公交站点
|
|
41
|
+
* const result = await inputTips.getTips('天安门', {
|
|
42
|
+
* city: '北京',
|
|
43
|
+
* datatype: 'bus'
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // 搜索公交线路
|
|
47
|
+
* const result = await inputTips.getTips('1路', {
|
|
48
|
+
* city: '北京',
|
|
49
|
+
* datatype: 'busline'
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
getTips(keywords: string, options?: Omit<InputTipsParams, 'keywords'>): Promise<InputTipsResponse>;
|
|
54
|
+
/**
|
|
55
|
+
* 获取 POI 输入提示
|
|
56
|
+
* 仅返回 POI 类型的建议
|
|
57
|
+
*
|
|
58
|
+
* @param keywords 查询关键词
|
|
59
|
+
* @param options 可选参数
|
|
60
|
+
* @returns 输入提示结果
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const result = await inputTips.getPOITips('餐厅', {
|
|
65
|
+
* city: '北京',
|
|
66
|
+
* type: '050000'
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
getPOITips(keywords: string, options?: Omit<InputTipsParams, 'keywords' | 'datatype'>): Promise<InputTipsResponse>;
|
|
71
|
+
/**
|
|
72
|
+
* 获取公交站点输入提示
|
|
73
|
+
* 仅返回公交站点类型的建议
|
|
74
|
+
*
|
|
75
|
+
* @param keywords 查询关键词
|
|
76
|
+
* @param options 可选参数
|
|
77
|
+
* @returns 输入提示结果
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const result = await inputTips.getBusTips('天安门', {
|
|
82
|
+
* city: '北京'
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
getBusTips(keywords: string, options?: Omit<InputTipsParams, 'keywords' | 'datatype'>): Promise<InputTipsResponse>;
|
|
87
|
+
/**
|
|
88
|
+
* 获取公交线路输入提示
|
|
89
|
+
* 仅返回公交线路类型的建议
|
|
90
|
+
*
|
|
91
|
+
* @param keywords 查询关键词
|
|
92
|
+
* @param options 可选参数
|
|
93
|
+
* @returns 输入提示结果
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const result = await inputTips.getBuslineTips('1路', {
|
|
98
|
+
* city: '北京'
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
getBuslineTips(keywords: string, options?: Omit<InputTipsParams, 'keywords' | 'datatype'>): Promise<InputTipsResponse>;
|
|
103
|
+
}
|