geocodio-library-node 1.10.0 → 1.13.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 +409 -1
- package/lib/__tests__/distance.test.js +365 -0
- package/lib/__tests__/geocodioLibraryNode.test.js +4 -4
- package/lib/index.d.ts +238 -11
- package/lib/index.js +493 -11
- package/package.json +3 -1
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
const Geocodio = require("../index.js");
|
|
2
|
+
const {
|
|
3
|
+
Coordinate,
|
|
4
|
+
DistanceMode,
|
|
5
|
+
DistanceUnits,
|
|
6
|
+
DistanceOrderBy,
|
|
7
|
+
DistanceSortOrder
|
|
8
|
+
} = require("../index.js");
|
|
9
|
+
|
|
10
|
+
describe("Coordinate class", () => {
|
|
11
|
+
it("Can create coordinate from numbers", () => {
|
|
12
|
+
const coord = new Coordinate(38.8977, -77.0365);
|
|
13
|
+
expect(coord.lat).toEqual(38.8977);
|
|
14
|
+
expect(coord.lng).toEqual(-77.0365);
|
|
15
|
+
expect(coord.id).toBeUndefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("Can create coordinate with id", () => {
|
|
19
|
+
const coord = new Coordinate(38.8977, -77.0365, "white_house");
|
|
20
|
+
expect(coord.lat).toEqual(38.8977);
|
|
21
|
+
expect(coord.lng).toEqual(-77.0365);
|
|
22
|
+
expect(coord.id).toEqual("white_house");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("Can convert to string format", () => {
|
|
26
|
+
const coord = new Coordinate(38.8977, -77.0365);
|
|
27
|
+
expect(coord.toString()).toEqual("38.8977,-77.0365");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("Can convert to string format with id", () => {
|
|
31
|
+
const coord = new Coordinate(38.8977, -77.0365, "white_house");
|
|
32
|
+
expect(coord.toString()).toEqual("38.8977,-77.0365,white_house");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("Can convert to object format", () => {
|
|
36
|
+
const coord = new Coordinate(38.8977, -77.0365);
|
|
37
|
+
expect(coord.toObject()).toEqual({ lat: 38.8977, lng: -77.0365 });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("Can convert to object format with id", () => {
|
|
41
|
+
const coord = new Coordinate(38.8977, -77.0365, "white_house");
|
|
42
|
+
expect(coord.toObject()).toEqual({
|
|
43
|
+
lat: 38.8977,
|
|
44
|
+
lng: -77.0365,
|
|
45
|
+
id: "white_house"
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("Can create from string", () => {
|
|
50
|
+
const coord = Coordinate.from("38.8977,-77.0365");
|
|
51
|
+
expect(coord.lat).toEqual(38.8977);
|
|
52
|
+
expect(coord.lng).toEqual(-77.0365);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("Can create from string with id", () => {
|
|
56
|
+
const coord = Coordinate.from("38.8977,-77.0365,white_house");
|
|
57
|
+
expect(coord.lat).toEqual(38.8977);
|
|
58
|
+
expect(coord.lng).toEqual(-77.0365);
|
|
59
|
+
expect(coord.id).toEqual("white_house");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("Can create from array", () => {
|
|
63
|
+
const coord = Coordinate.from([38.8977, -77.0365]);
|
|
64
|
+
expect(coord.lat).toEqual(38.8977);
|
|
65
|
+
expect(coord.lng).toEqual(-77.0365);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("Can create from array with id", () => {
|
|
69
|
+
const coord = Coordinate.from([38.8977, -77.0365, "white_house"]);
|
|
70
|
+
expect(coord.lat).toEqual(38.8977);
|
|
71
|
+
expect(coord.lng).toEqual(-77.0365);
|
|
72
|
+
expect(coord.id).toEqual("white_house");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("Can create from object", () => {
|
|
76
|
+
const coord = Coordinate.from({ lat: 38.8977, lng: -77.0365 });
|
|
77
|
+
expect(coord.lat).toEqual(38.8977);
|
|
78
|
+
expect(coord.lng).toEqual(-77.0365);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("Can create from object with id", () => {
|
|
82
|
+
const coord = Coordinate.from({
|
|
83
|
+
lat: 38.8977,
|
|
84
|
+
lng: -77.0365,
|
|
85
|
+
id: "white_house"
|
|
86
|
+
});
|
|
87
|
+
expect(coord.lat).toEqual(38.8977);
|
|
88
|
+
expect(coord.lng).toEqual(-77.0365);
|
|
89
|
+
expect(coord.id).toEqual("white_house");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("Can create from Coordinate instance", () => {
|
|
93
|
+
const original = new Coordinate(38.8977, -77.0365, "white_house");
|
|
94
|
+
const coord = Coordinate.from(original);
|
|
95
|
+
expect(coord).toBe(original);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("Throws error for invalid latitude", () => {
|
|
99
|
+
expect(() => new Coordinate(100, -77.0365)).toThrow(
|
|
100
|
+
"Latitude must be between -90 and 90"
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("Throws error for invalid longitude", () => {
|
|
105
|
+
expect(() => new Coordinate(38.8977, 200)).toThrow(
|
|
106
|
+
"Longitude must be between -180 and 180"
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("Throws error for non-numeric latitude", () => {
|
|
111
|
+
expect(() => new Coordinate("not a number", -77.0365)).toThrow(
|
|
112
|
+
"Latitude must be a number"
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("Throws error for invalid string format", () => {
|
|
117
|
+
expect(() => Coordinate.fromString("invalid")).toThrow(
|
|
118
|
+
"Invalid coordinate string"
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("Throws error for non-numeric coordinate values", () => {
|
|
123
|
+
expect(() => Coordinate.fromString("abc,def")).toThrow(
|
|
124
|
+
"Invalid coordinate values"
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("Distance enums", () => {
|
|
130
|
+
it("DistanceMode has correct values", () => {
|
|
131
|
+
expect(DistanceMode.Straightline).toEqual("straightline");
|
|
132
|
+
expect(DistanceMode.Driving).toEqual("driving");
|
|
133
|
+
expect(DistanceMode.Haversine).toEqual("haversine");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("DistanceUnits has correct values", () => {
|
|
137
|
+
expect(DistanceUnits.Miles).toEqual("miles");
|
|
138
|
+
expect(DistanceUnits.Kilometers).toEqual("km");
|
|
139
|
+
expect(DistanceUnits.Km).toEqual("km");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("DistanceOrderBy has correct values", () => {
|
|
143
|
+
expect(DistanceOrderBy.Distance).toEqual("distance");
|
|
144
|
+
expect(DistanceOrderBy.Duration).toEqual("duration");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("DistanceSortOrder has correct values", () => {
|
|
148
|
+
expect(DistanceSortOrder.Asc).toEqual("asc");
|
|
149
|
+
expect(DistanceSortOrder.Desc).toEqual("desc");
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("Distance API", () => {
|
|
154
|
+
const geocoder = new Geocodio();
|
|
155
|
+
|
|
156
|
+
// White House coordinates
|
|
157
|
+
const whiteHouse = "38.8977,-77.0365,white_house";
|
|
158
|
+
// Capitol Building
|
|
159
|
+
const capitol = "38.8899,-77.0091,capitol";
|
|
160
|
+
// Washington Monument
|
|
161
|
+
const monument = "38.8895,-77.0353,monument";
|
|
162
|
+
|
|
163
|
+
it("Can calculate distance from single origin to destinations", () => {
|
|
164
|
+
expect.assertions(3);
|
|
165
|
+
|
|
166
|
+
return geocoder.distance(whiteHouse, [capitol, monument]).then(response => {
|
|
167
|
+
expect(response.origin).toBeDefined();
|
|
168
|
+
expect(response.destinations.length).toEqual(2);
|
|
169
|
+
const ids = response.destinations.map(d => d.id);
|
|
170
|
+
expect(ids).toContain("capitol");
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("Can calculate distance with Coordinate objects", () => {
|
|
175
|
+
expect.assertions(3);
|
|
176
|
+
|
|
177
|
+
const origin = new Coordinate(38.8977, -77.0365, "white_house");
|
|
178
|
+
const destinations = [
|
|
179
|
+
new Coordinate(38.8899, -77.0091, "capitol"),
|
|
180
|
+
new Coordinate(38.8895, -77.0353, "monument")
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
return geocoder.distance(origin, destinations).then(response => {
|
|
184
|
+
expect(response.origin).toBeDefined();
|
|
185
|
+
expect(response.destinations.length).toEqual(2);
|
|
186
|
+
const ids = response.destinations.map(d => d.id);
|
|
187
|
+
expect(ids).toContain("capitol");
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("Can calculate distance with array format", () => {
|
|
192
|
+
expect.assertions(3);
|
|
193
|
+
|
|
194
|
+
return geocoder
|
|
195
|
+
.distance(
|
|
196
|
+
[38.8977, -77.0365, "white_house"],
|
|
197
|
+
[
|
|
198
|
+
[38.8899, -77.0091, "capitol"],
|
|
199
|
+
[38.8895, -77.0353, "monument"]
|
|
200
|
+
]
|
|
201
|
+
)
|
|
202
|
+
.then(response => {
|
|
203
|
+
expect(response.origin).toBeDefined();
|
|
204
|
+
expect(response.destinations.length).toEqual(2);
|
|
205
|
+
const ids = response.destinations.map(d => d.id);
|
|
206
|
+
expect(ids).toContain("capitol");
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("Can calculate distance with driving mode", () => {
|
|
211
|
+
expect.assertions(2);
|
|
212
|
+
|
|
213
|
+
return geocoder
|
|
214
|
+
.distance(whiteHouse, [capitol], { mode: DistanceMode.Driving })
|
|
215
|
+
.then(response => {
|
|
216
|
+
expect(response.mode).toEqual("driving");
|
|
217
|
+
expect(response.destinations[0].duration_seconds).toBeDefined();
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("Can calculate distance in kilometers", () => {
|
|
222
|
+
expect.assertions(1);
|
|
223
|
+
|
|
224
|
+
return geocoder
|
|
225
|
+
.distance(whiteHouse, [capitol], { units: DistanceUnits.Kilometers })
|
|
226
|
+
.then(response => {
|
|
227
|
+
expect(response.destinations[0].distance_km).toBeDefined();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("Can use haversine mode (maps to straightline)", () => {
|
|
232
|
+
expect.assertions(1);
|
|
233
|
+
|
|
234
|
+
return geocoder
|
|
235
|
+
.distance(whiteHouse, [capitol], { mode: DistanceMode.Haversine })
|
|
236
|
+
.then(response => {
|
|
237
|
+
expect(response.mode).toEqual("straightline");
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("Can limit max results", () => {
|
|
242
|
+
expect.assertions(1);
|
|
243
|
+
|
|
244
|
+
return geocoder
|
|
245
|
+
.distance(whiteHouse, [capitol, monument], { maxResults: 1 })
|
|
246
|
+
.then(response => {
|
|
247
|
+
expect(response.destinations.length).toEqual(1);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe("Distance Matrix API", () => {
|
|
253
|
+
const geocoder = new Geocodio();
|
|
254
|
+
|
|
255
|
+
const origins = [
|
|
256
|
+
{ lat: 38.8977, lng: -77.0365, id: "white_house" },
|
|
257
|
+
{ lat: 38.8899, lng: -77.0091, id: "capitol" }
|
|
258
|
+
];
|
|
259
|
+
|
|
260
|
+
const destinations = [
|
|
261
|
+
{ lat: 38.8895, lng: -77.0353, id: "monument" },
|
|
262
|
+
{ lat: 38.9072, lng: -77.0369, id: "dupont" }
|
|
263
|
+
];
|
|
264
|
+
|
|
265
|
+
it("Can calculate distance matrix", () => {
|
|
266
|
+
expect.assertions(3);
|
|
267
|
+
|
|
268
|
+
return geocoder.distanceMatrix(origins, destinations).then(response => {
|
|
269
|
+
expect(response.mode).toBeDefined();
|
|
270
|
+
expect(response.results.length).toEqual(2);
|
|
271
|
+
expect(response.results[0].destinations.length).toBeGreaterThanOrEqual(1);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("Can calculate distance matrix with string coordinates", () => {
|
|
276
|
+
expect.assertions(2);
|
|
277
|
+
|
|
278
|
+
return geocoder
|
|
279
|
+
.distanceMatrix(
|
|
280
|
+
["38.8977,-77.0365,origin1", "38.8899,-77.0091,origin2"],
|
|
281
|
+
["38.8895,-77.0353,dest1"]
|
|
282
|
+
)
|
|
283
|
+
.then(response => {
|
|
284
|
+
expect(response.results.length).toEqual(2);
|
|
285
|
+
expect(response.results[0].origin.id).toEqual("origin1");
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("Can calculate distance matrix with driving mode", () => {
|
|
290
|
+
expect.assertions(2);
|
|
291
|
+
|
|
292
|
+
return geocoder
|
|
293
|
+
.distanceMatrix(origins, destinations, { mode: DistanceMode.Driving })
|
|
294
|
+
.then(response => {
|
|
295
|
+
expect(response.mode).toEqual("driving");
|
|
296
|
+
expect(
|
|
297
|
+
response.results[0].destinations[0].duration_seconds
|
|
298
|
+
).toBeDefined();
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("Can calculate distance matrix with filtering options", () => {
|
|
303
|
+
expect.assertions(1);
|
|
304
|
+
|
|
305
|
+
return geocoder
|
|
306
|
+
.distanceMatrix(origins, destinations, {
|
|
307
|
+
maxResults: 1,
|
|
308
|
+
orderBy: DistanceOrderBy.Distance,
|
|
309
|
+
sortOrder: DistanceSortOrder.Asc
|
|
310
|
+
})
|
|
311
|
+
.then(response => {
|
|
312
|
+
expect(response.results[0].destinations.length).toBeLessThanOrEqual(1);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe("Geocode with distance", () => {
|
|
318
|
+
const geocoder = new Geocodio();
|
|
319
|
+
|
|
320
|
+
it("Can geocode with distance to destinations", () => {
|
|
321
|
+
expect.assertions(2);
|
|
322
|
+
|
|
323
|
+
return geocoder
|
|
324
|
+
.geocode("1600 Pennsylvania Ave NW, Washington DC", [], null, {
|
|
325
|
+
destinations: ["38.8899,-77.0091,capitol"]
|
|
326
|
+
})
|
|
327
|
+
.then(response => {
|
|
328
|
+
expect(response.results[0]).toBeDefined();
|
|
329
|
+
// Note: destinations may or may not be included depending on API version
|
|
330
|
+
expect(response.results.length).toBeGreaterThan(0);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
describe("Reverse geocode with distance", () => {
|
|
336
|
+
const geocoder = new Geocodio();
|
|
337
|
+
|
|
338
|
+
it("Can reverse geocode with distance to destinations", () => {
|
|
339
|
+
expect.assertions(2);
|
|
340
|
+
|
|
341
|
+
return geocoder
|
|
342
|
+
.reverse("38.8977,-77.0365", [], null, {
|
|
343
|
+
destinations: ["38.8899,-77.0091,capitol"]
|
|
344
|
+
})
|
|
345
|
+
.then(response => {
|
|
346
|
+
expect(response.results[0]).toBeDefined();
|
|
347
|
+
expect(response.results.length).toBeGreaterThan(0);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
describe("Distance Matrix Jobs API", () => {
|
|
353
|
+
const geocoder = new Geocodio();
|
|
354
|
+
|
|
355
|
+
it("Can list distance matrix jobs", () => {
|
|
356
|
+
expect.assertions(1);
|
|
357
|
+
|
|
358
|
+
return geocoder.distanceMatrixJobs().then(response => {
|
|
359
|
+
expect(response.data).toBeDefined();
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// Note: Creating, checking status, and deleting jobs is tested in integration
|
|
364
|
+
// as it requires actual job creation which takes time
|
|
365
|
+
});
|
|
@@ -116,10 +116,10 @@ describe("geocoder", () => {
|
|
|
116
116
|
.then(response => {
|
|
117
117
|
expect(
|
|
118
118
|
response.results[0].response.results[0].formatted_address
|
|
119
|
-
).toEqual("
|
|
119
|
+
).toEqual("116 W Washington St, Nashville, NC 27856");
|
|
120
120
|
expect(
|
|
121
121
|
response.results[1].response.results[0].formatted_address
|
|
122
|
-
).toEqual("
|
|
122
|
+
).toEqual("3026 S 1st St, Garland, TX 75041");
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
125
|
|
|
@@ -134,10 +134,10 @@ describe("geocoder", () => {
|
|
|
134
134
|
.then(response => {
|
|
135
135
|
expect(
|
|
136
136
|
response.results[0].response.results[0].formatted_address
|
|
137
|
-
).toEqual("
|
|
137
|
+
).toEqual("116 W Washington St, Nashville, NC 27856");
|
|
138
138
|
expect(
|
|
139
139
|
response.results[1].response.results[0].formatted_address
|
|
140
|
-
).toEqual("
|
|
140
|
+
).toEqual("3026 S 1st St, Garland, TX 75041");
|
|
141
141
|
});
|
|
142
142
|
});
|
|
143
143
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,176 @@
|
|
|
1
1
|
declare module 'geocodio-library-node' {
|
|
2
|
+
// Distance API Enums
|
|
3
|
+
export enum DistanceMode {
|
|
4
|
+
Straightline = 'straightline',
|
|
5
|
+
Driving = 'driving',
|
|
6
|
+
Haversine = 'haversine' // Alias for straightline (backward compat)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export enum DistanceUnits {
|
|
10
|
+
Miles = 'miles',
|
|
11
|
+
Kilometers = 'km',
|
|
12
|
+
Km = 'km' // Alias
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export enum DistanceOrderBy {
|
|
16
|
+
Distance = 'distance',
|
|
17
|
+
Duration = 'duration'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export enum DistanceSortOrder {
|
|
21
|
+
Asc = 'asc',
|
|
22
|
+
Desc = 'desc'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Coordinate class for distance calculations
|
|
26
|
+
export class Coordinate {
|
|
27
|
+
readonly lat: number;
|
|
28
|
+
readonly lng: number;
|
|
29
|
+
readonly id?: string;
|
|
30
|
+
|
|
31
|
+
constructor(lat: number, lng: number, id?: string);
|
|
32
|
+
|
|
33
|
+
static from(input: CoordinateInput): Coordinate;
|
|
34
|
+
static fromString(input: string): Coordinate;
|
|
35
|
+
static fromArray(input: [number, number] | [number, number, string]): Coordinate;
|
|
36
|
+
|
|
37
|
+
toString(): string;
|
|
38
|
+
toObject(): { lat: number; lng: number; id?: string };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Coordinate input types (accept multiple formats)
|
|
42
|
+
export type CoordinateInput =
|
|
43
|
+
| Coordinate
|
|
44
|
+
| string // "lat,lng" or "lat,lng,id"
|
|
45
|
+
| [number, number] // [lat, lng]
|
|
46
|
+
| [number, number, string] // [lat, lng, id]
|
|
47
|
+
| { lat: number; lng: number; id?: string };
|
|
48
|
+
|
|
49
|
+
// Distance API Response Types
|
|
50
|
+
export interface DistanceDestination {
|
|
51
|
+
query: string;
|
|
52
|
+
location: [number, number];
|
|
53
|
+
id?: string;
|
|
54
|
+
distance_miles: number;
|
|
55
|
+
distance_km: number;
|
|
56
|
+
duration_seconds?: number; // Only with driving mode
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface DistanceOrigin {
|
|
60
|
+
query: string;
|
|
61
|
+
location: [number, number];
|
|
62
|
+
id?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface DistanceResponse {
|
|
66
|
+
origin: DistanceOrigin;
|
|
67
|
+
mode: string;
|
|
68
|
+
destinations: DistanceDestination[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface DistanceMatrixResult {
|
|
72
|
+
origin: DistanceOrigin;
|
|
73
|
+
destinations: DistanceDestination[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface DistanceMatrixResponse {
|
|
77
|
+
mode: string;
|
|
78
|
+
results: DistanceMatrixResult[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Distance options
|
|
82
|
+
export interface DistanceOptions {
|
|
83
|
+
mode?: DistanceMode | 'straightline' | 'driving' | 'haversine';
|
|
84
|
+
units?: DistanceUnits | 'miles' | 'kilometers';
|
|
85
|
+
maxResults?: number;
|
|
86
|
+
maxDistance?: number;
|
|
87
|
+
maxDuration?: number;
|
|
88
|
+
minDistance?: number;
|
|
89
|
+
minDuration?: number;
|
|
90
|
+
orderBy?: DistanceOrderBy | 'distance' | 'duration';
|
|
91
|
+
sortOrder?: DistanceSortOrder | 'asc' | 'desc';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Distance Job Types
|
|
95
|
+
export interface DistanceJobResponse {
|
|
96
|
+
id: number;
|
|
97
|
+
identifier: string;
|
|
98
|
+
status: 'ENQUEUED' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
|
|
99
|
+
name: string;
|
|
100
|
+
created_at: string;
|
|
101
|
+
origins_count: number;
|
|
102
|
+
destinations_count: number;
|
|
103
|
+
total_calculations: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface DistanceJobStatusResponse {
|
|
107
|
+
data: {
|
|
108
|
+
id: number;
|
|
109
|
+
identifier: string;
|
|
110
|
+
name: string;
|
|
111
|
+
status: 'ENQUEUED' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
|
|
112
|
+
progress: number;
|
|
113
|
+
download_url?: string;
|
|
114
|
+
total_calculations: number;
|
|
115
|
+
calculations_completed: number;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface DistanceJobsListResponse {
|
|
120
|
+
current_page: number;
|
|
121
|
+
data: Array<{
|
|
122
|
+
id: number;
|
|
123
|
+
identifier: string;
|
|
124
|
+
name: string;
|
|
125
|
+
status: 'ENQUEUED' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
|
|
126
|
+
progress: number;
|
|
127
|
+
total_calculations: number;
|
|
128
|
+
calculations_completed: number;
|
|
129
|
+
created_at: string;
|
|
130
|
+
}>;
|
|
131
|
+
first_page_url: string;
|
|
132
|
+
from: number;
|
|
133
|
+
last_page: number;
|
|
134
|
+
last_page_url: string;
|
|
135
|
+
next_page_url: string | null;
|
|
136
|
+
path: string;
|
|
137
|
+
per_page: number;
|
|
138
|
+
prev_page_url: string | null;
|
|
139
|
+
to: number;
|
|
140
|
+
total: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface DistanceJobOptions extends DistanceOptions {
|
|
144
|
+
callbackUrl?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Geocode with distance options
|
|
148
|
+
export interface GeocodeDistanceOptions {
|
|
149
|
+
destinations?: CoordinateInput[];
|
|
150
|
+
distanceMode?: DistanceMode | 'straightline' | 'driving' | 'haversine';
|
|
151
|
+
distanceUnits?: DistanceUnits | 'miles' | 'kilometers';
|
|
152
|
+
distanceMaxResults?: number;
|
|
153
|
+
distanceMaxDistance?: number;
|
|
154
|
+
distanceMaxDuration?: number;
|
|
155
|
+
distanceMinDistance?: number;
|
|
156
|
+
distanceMinDuration?: number;
|
|
157
|
+
distanceOrderBy?: DistanceOrderBy | 'distance' | 'duration';
|
|
158
|
+
distanceSortOrder?: DistanceSortOrder | 'asc' | 'desc';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Enhanced geocoded address with distance info
|
|
162
|
+
export interface GeocodedAddressWithDistance extends GeocodedAddress {
|
|
163
|
+
destinations?: DistanceDestination[];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface SingleGeocodeResponseWithDistance extends SingleGeocodeResponse {
|
|
167
|
+
results: GeocodedAddressWithDistance[];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface ReverseGeocodeResponseWithDistance extends ReverseGeocodeResponse {
|
|
171
|
+
results: GeocodedAddressWithDistance[];
|
|
172
|
+
}
|
|
173
|
+
|
|
2
174
|
export interface AddressComponents {
|
|
3
175
|
number?: string;
|
|
4
176
|
predirectional?: string;
|
|
@@ -17,6 +189,8 @@ declare module 'geocodio-library-node' {
|
|
|
17
189
|
postal_code?: string; // Alternative to zip used in some API calls
|
|
18
190
|
}
|
|
19
191
|
|
|
192
|
+
export type AddressInputComponents = Pick<AddressComponents, "street" | "city" | "county" | "state" | "postal_code" | "country">
|
|
193
|
+
|
|
20
194
|
export type GeocodeAccuracyType =
|
|
21
195
|
| 'rooftop'
|
|
22
196
|
| 'point'
|
|
@@ -224,26 +398,28 @@ declare module 'geocodio-library-node' {
|
|
|
224
398
|
formatted_address: string;
|
|
225
399
|
};
|
|
226
400
|
results: GeocodedAddress[];
|
|
401
|
+
_warnings?: string[];
|
|
227
402
|
}
|
|
228
403
|
|
|
229
|
-
export interface BatchGeocodeResponse {
|
|
230
|
-
results: Array<{
|
|
231
|
-
query:
|
|
404
|
+
export interface BatchGeocodeResponse<Q extends string | AddressInputComponents, T extends Array<Q> | Record<string, Q>> {
|
|
405
|
+
results: T extends Array<Q> ? Array<{
|
|
406
|
+
query: Q;
|
|
232
407
|
response: SingleGeocodeResponse;
|
|
233
|
-
}>
|
|
408
|
+
}> : Record<keyof T, {
|
|
234
409
|
response: SingleGeocodeResponse;
|
|
235
410
|
}>;
|
|
236
411
|
}
|
|
237
412
|
|
|
238
413
|
export interface ReverseGeocodeResponse {
|
|
239
414
|
results: GeocodedAddress[];
|
|
415
|
+
_warnings?: string[];
|
|
240
416
|
}
|
|
241
417
|
|
|
242
|
-
export interface BatchReverseGeocodeResponse {
|
|
243
|
-
results: Array<{
|
|
244
|
-
query:
|
|
418
|
+
export interface BatchReverseGeocodeResponse<Q extends string | [number, number], T extends Array<Q> | Record<string, Q>> {
|
|
419
|
+
results: T extends Array<Q> ? Array<{
|
|
420
|
+
query: Q;
|
|
245
421
|
response: ReverseGeocodeResponse;
|
|
246
|
-
}>
|
|
422
|
+
}> : Record<keyof T, {
|
|
247
423
|
response: ReverseGeocodeResponse;
|
|
248
424
|
}>;
|
|
249
425
|
}
|
|
@@ -259,12 +435,63 @@ declare module 'geocodio-library-node' {
|
|
|
259
435
|
export default class Geocodio {
|
|
260
436
|
constructor(apiKey?: string, hostname?: string, apiVersion?: string);
|
|
261
437
|
|
|
262
|
-
|
|
263
|
-
geocode(query:
|
|
438
|
+
// Geocoding methods
|
|
439
|
+
geocode(query: string | AddressInputComponents, fields?: FieldOption[], limit?: number): Promise<SingleGeocodeResponse>;
|
|
440
|
+
geocode<Q extends string | AddressInputComponents, T extends Array<Q> | Record<string, Q>>(query: T, fields?: FieldOption[], limit?: number): Promise<BatchGeocodeResponse<Q, T>>;
|
|
264
441
|
|
|
442
|
+
// Geocode with distance
|
|
443
|
+
geocode(
|
|
444
|
+
query: string | AddressInputComponents,
|
|
445
|
+
fields?: FieldOption[],
|
|
446
|
+
limit?: number,
|
|
447
|
+
distanceOptions?: GeocodeDistanceOptions
|
|
448
|
+
): Promise<SingleGeocodeResponseWithDistance>;
|
|
449
|
+
|
|
450
|
+
// Reverse geocoding methods
|
|
265
451
|
reverse(query: string | [number, number], fields?: FieldOption[], limit?: number): Promise<ReverseGeocodeResponse>;
|
|
266
|
-
reverse
|
|
452
|
+
reverse<Q extends string | [number, number], T extends Array<Q> | Record<string, Q>>(query: T, fields?: FieldOption[], limit?: number): Promise<BatchReverseGeocodeResponse<Q, T>>;
|
|
453
|
+
|
|
454
|
+
// Reverse with distance
|
|
455
|
+
reverse(
|
|
456
|
+
query: string | [number, number],
|
|
457
|
+
fields?: FieldOption[],
|
|
458
|
+
limit?: number,
|
|
459
|
+
distanceOptions?: GeocodeDistanceOptions
|
|
460
|
+
): Promise<ReverseGeocodeResponseWithDistance>;
|
|
461
|
+
|
|
462
|
+
// Distance API - Single origin to multiple destinations (GET)
|
|
463
|
+
distance(
|
|
464
|
+
origin: CoordinateInput,
|
|
465
|
+
destinations: CoordinateInput[],
|
|
466
|
+
options?: DistanceOptions
|
|
467
|
+
): Promise<DistanceResponse>;
|
|
468
|
+
|
|
469
|
+
// Distance Matrix API - Multiple origins × destinations (POST)
|
|
470
|
+
distanceMatrix(
|
|
471
|
+
origins: CoordinateInput[],
|
|
472
|
+
destinations: CoordinateInput[],
|
|
473
|
+
options?: DistanceOptions
|
|
474
|
+
): Promise<DistanceMatrixResponse>;
|
|
475
|
+
|
|
476
|
+
// Async Distance Matrix Job methods
|
|
477
|
+
createDistanceMatrixJob(
|
|
478
|
+
name: string,
|
|
479
|
+
origins: CoordinateInput[] | number, // Array or list ID
|
|
480
|
+
destinations: CoordinateInput[] | number,
|
|
481
|
+
options?: DistanceJobOptions
|
|
482
|
+
): Promise<DistanceJobResponse>;
|
|
483
|
+
|
|
484
|
+
distanceMatrixJobStatus(id: string | number): Promise<DistanceJobStatusResponse>;
|
|
485
|
+
|
|
486
|
+
distanceMatrixJobs(page?: number): Promise<DistanceJobsListResponse>;
|
|
487
|
+
|
|
488
|
+
getDistanceMatrixJobResults(id: string | number): Promise<DistanceMatrixResponse>;
|
|
489
|
+
|
|
490
|
+
downloadDistanceMatrixJob(id: string | number, filePath: string): Promise<void>;
|
|
491
|
+
|
|
492
|
+
deleteDistanceMatrixJob(id: string | number): Promise<void>;
|
|
267
493
|
|
|
494
|
+
// List API
|
|
268
495
|
list: {
|
|
269
496
|
create(filename: string, direction: string, format: string, callback: string): Promise<ListResponse>;
|
|
270
497
|
status(listId: number): Promise<unknown>;
|