-
Notifications
You must be signed in to change notification settings - Fork 17
/
geocode.js
30 lines (26 loc) · 1.13 KB
/
geocode.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
const request = require('request');
var geocodeAddress = (address, callback) => {
request({
url: 'http://mapquestapi.com/geocoding/v1/address?key=gi58AiucSCUsY9AbnjXJxlr0zvkN3Ux8&location=' + address,
json: true
}, (error, response, body) => {
if (error != null) // mistake from user end
{
callback("Please check your Internet connection and try again later !");
}
else if (body.info.statuscode == 400) { // mistake from server end
callback("Hey, no such place exist try entering some other place !");
}
else if (body.info.statuscode == 0){
callback(undefined, {
latitute: body.results[0].locations[0].latLng.lat,
longitude: body.results[0].locations[0].latLng.lng,
street : body.results[0].locations[0].street,
area5 : body.results[0].locations[0].adminArea5,
state : body.results[0].locations[0].adminArea3,
country : body.results[0].locations[0].adminArea1
});
}
});
};
module.exports.geocodeAddress = geocodeAddress;