-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathopencage-docs-forward.js
32 lines (30 loc) · 984 Bytes
/
opencage-docs-forward.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* eslint-disable no-console */
const opencage = require('..');
opencage
.geocode({ q: 'Theresienhöhe 11, München' })
.then((data) => {
// console.log(JSON.stringify(data));
if (data.results.length > 0) {
const place = data.results[0];
console.log(place.formatted);
console.log(place.geometry);
console.log(place.annotations.timezone.name);
} else {
console.log('status', data.status.message);
console.log('total_results', data.total_results);
}
})
.catch((error) => {
console.log('error', error.message);
// console.log(JSON.stringify(error));
// other possible response codes:
// https://opencagedata.com/api#codes
if (error.status.code === 402) {
console.log('hit free trial daily limit');
console.log('become a customer: https://opencagedata.com/pricing');
}
});
// ... prints
// Theresienhöhe 11, 80339 Munich, Germany
// { lat: 48.1341651, lng: 11.5464794 }
// Europe/Berlin