-
Notifications
You must be signed in to change notification settings - Fork 0
/
getLatLng.js
26 lines (24 loc) · 838 Bytes
/
getLatLng.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
const request = require('request');
var getLatLng = (url) => {
return new Promise((resolve, reject) => {
request.get({
url: url,
json: true,
}, (err, res, data) => {
if (err) {
reject('Error:', err);
} else if (res.statusCode !== 200) {
reject('Status:', res.statusCode);
} else if (data.status === 'ZERO_RESULTS'){
reject('Not found data for this address.');
}else if(data.status === 'OK'){
resolve({
address: data.results[0].formatted_address,
lat: data.results[0].geometry.location.lat,
lng: data.results[0].geometry.location.lng
});
}
});
});
}
exports.getLatLng = getLatLng ;