mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 11:57:33 +08:00
Add node-geocoded definition.
This commit is contained in:
92
types/node-geocoder/index.d.ts
vendored
Normal file
92
types/node-geocoder/index.d.ts
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
// Type definitions for node-geocoder 3.19
|
||||
// Project: https://github.com/nchaulet/node-geocoder#readme
|
||||
// Definitions by: Krzysztof Rosinski <https://github.com/rosek86>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
declare namespace node_geocoder {
|
||||
type Providers =
|
||||
'google' | 'here' | 'freegeoip' |
|
||||
'datasciencetoolkit' | 'openstreetmap' |
|
||||
'locationiq' | 'mapquest' | 'openmapquest' |
|
||||
'agol' | 'tomtom' | 'nominatimmapquest' |
|
||||
'opencage' | 'smartyStreet' | 'geocodio' |
|
||||
'yandex' | 'teleport' | 'opendatafrance' |
|
||||
'pickpoint';
|
||||
|
||||
interface Options {
|
||||
provider: Providers;
|
||||
httpAdapter?: 'https' | 'http' | 'request';
|
||||
clientId?: string;
|
||||
apiKey?: string;
|
||||
language?: string;
|
||||
region?: string;
|
||||
appId?: string;
|
||||
appCode?: string;
|
||||
politicalView?: string;
|
||||
country?: string;
|
||||
state?: string;
|
||||
host?: string;
|
||||
email?: string;
|
||||
client_id?: string;
|
||||
client_secret?: string;
|
||||
auth_id?: string;
|
||||
auth_token?: string;
|
||||
timeout?: number;
|
||||
formatterPattern?: string;
|
||||
formatter?: any;
|
||||
}
|
||||
|
||||
interface Location {
|
||||
lat: number;
|
||||
lon: number;
|
||||
}
|
||||
|
||||
interface Entry {
|
||||
formattedAddress?: string;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
extra?: {
|
||||
googlePlaceId?: string;
|
||||
confidence?: number;
|
||||
};
|
||||
administrativeLevels?: {
|
||||
level1long?: string;
|
||||
level1short?: string;
|
||||
level2long?: string;
|
||||
level2short?: string;
|
||||
};
|
||||
city?: string;
|
||||
streetName?: string;
|
||||
streetNumber?: string;
|
||||
country?: string;
|
||||
countryCode?: string;
|
||||
zipcode?: string;
|
||||
provider?: string;
|
||||
}
|
||||
|
||||
interface Query {
|
||||
address?: string;
|
||||
country?: string;
|
||||
countryCode?: string;
|
||||
zipcode?: string;
|
||||
minConfidence?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
interface BatchResult {
|
||||
error: any;
|
||||
value: Entry[];
|
||||
}
|
||||
|
||||
class Geocoder {
|
||||
geocode(query: string | Query, cb?: (err: any, data: Entry[]) => void): Promise<Entry[]>;
|
||||
batchGeocode(queries: string[] | Query[], cb?: (err: any, data: BatchResult[]) => void): Promise<BatchResult[]>;
|
||||
reverse(loc: Location, cb?: (err: any, data: Entry[]) => void): Promise<Entry[]>;
|
||||
}
|
||||
}
|
||||
|
||||
declare function node_geocoder(options: node_geocoder.Options): node_geocoder.Geocoder;
|
||||
|
||||
export = node_geocoder;
|
||||
54
types/node-geocoder/node-geocoder-tests.ts
Normal file
54
types/node-geocoder/node-geocoder-tests.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as NodeGeocoder from 'node-geocoder';
|
||||
|
||||
const geocoder = NodeGeocoder({
|
||||
provider: 'google',
|
||||
httpAdapter: 'https',
|
||||
});
|
||||
|
||||
let results: NodeGeocoder.Entry[] | undefined;
|
||||
|
||||
geocoder.geocode('Poland').then((entries) => {
|
||||
results = entries;
|
||||
}).then(() => {
|
||||
if (results) {
|
||||
console.log(JSON.stringify(results, null, 2));
|
||||
}
|
||||
});
|
||||
|
||||
geocoder.geocode('Poland', (err: any, entries: NodeGeocoder.Entry[]) => {
|
||||
console.log(JSON.stringify(entries, null, 2));
|
||||
});
|
||||
|
||||
const query: NodeGeocoder.Query = { address: 'Poland' };
|
||||
|
||||
geocoder.geocode(query).then((entries) => {
|
||||
console.log(JSON.stringify(entries, null, 2));
|
||||
});
|
||||
|
||||
geocoder.geocode(query, (err: any, entries: NodeGeocoder.Entry[]) => {
|
||||
console.log(JSON.stringify(entries, null, 2));
|
||||
});
|
||||
|
||||
geocoder.batchGeocode([ 'Kraków', 'Warszawa' ]).then((entries) => {
|
||||
if (entries.length !== 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
const k = entries[0];
|
||||
if (!k.error) {
|
||||
console.log(JSON.stringify(k.value, null, 2));
|
||||
}
|
||||
|
||||
const w = entries[1];
|
||||
if (!w.error) {
|
||||
console.log(JSON.stringify(w.value, null, 2));
|
||||
}
|
||||
});
|
||||
|
||||
geocoder.reverse({ lat: 50.06465, lon: 19.9449799 }).then((entries) => {
|
||||
console.log(JSON.stringify(entries, null, 2));
|
||||
});
|
||||
|
||||
geocoder.reverse({ lat: 50.06465, lon: 19.9449799 }).then((entries) => {
|
||||
console.log(JSON.stringify(entries, null, 2));
|
||||
});
|
||||
22
types/node-geocoder/tsconfig.json
Normal file
22
types/node-geocoder/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"node-geocoder-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/node-geocoder/tslint.json
Normal file
1
types/node-geocoder/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user