Skip to content

Commit

Permalink
Create getlocation.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dwivedikunal100 authored Mar 14, 2019
1 parent 19b6054 commit 4f426e3
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions helper./getlocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var NodeGeocoder = require("node-geocoder");
var twitter = require("./gettweet.js");
var options = {
provider: "google",
httpAdapter: "https",
apiKey: "Your API key here",
formatter: null
};
var geocoder = NodeGeocoder(options);

var methods = {};

methods.locator = function(callback) {
twitter.gettweet(function(response) {
if (response.statusCode != 200) {
console.log("No request made to google maps");
return callback(response);
} else {
console.log("Request made to google maps");
geocoder.geocode(response.location, function(err, data) {
if (err) {
console.log("Error occured........" + err);
return callback({
statusCode: 400,
statusMessage: JSON.stringify(err)
});
} else {
console.log("Location successfully returned...");
console.log(data);
return callback({
statusCode: 200,
latitude: data[0].latitude,
longitude: data[0].longitude
});
}
});
}
});
};

module.exports = methods;

0 comments on commit 4f426e3

Please sign in to comment.