You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

address-to-geocode

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

address-to-geocode - npm Package Compare versions

Comparing version

to
0.2.0

test/index.js

49

index.js
// Dependnecies
var Geocoder = require("node-geocoder").getGeocoder("google");
var myLocation = "New York";
// Get location
Geocoder.geocode({
address: myLocation
}, function(err, guess) {
if (err) { throw err; }
/**
* AddressToGeocode
* Converts a string representing an address to geocode data.
*
* @name AddressToGeocode
* @function
* @param {String} address The searched location
* @param {Function} callback The callback function
* @return {Object} AddressToGeocode function
*/
var AddressToGeocode = function (address, callback) {
Geocoder.geocode({
address: address
}, function(err, guess) {
if (err) { return callback(err); }
callback(null, AddressToGeocode.handleLocation(guess));
});
return AddressToGeocode;
};
/**
* handleLocation
*
* @name handleLocation
* @function
* @param {Array} guess Locations returned by Geocoder
* @return {Object} An object containing `lat` and `lng` fields.
*/
AddressToGeocode.handleLocation = function (guess) {
if (!guess || !guess.length) {
return console.error("No location found");
return {};
}
return {
lat: guess[0].latitude,
lng: guess[0].longitude
};
};
console.log(myLocation + ": (" + guess[0].latitude + ", " + guess[0].longitude + ")");
console.log("----");
console.log("Results:", guess);
});
module.exports = AddressToGeocode;
{
"name": "address-to-geocode",
"version": "0.1.0",
"version": "0.2.0",
"description": "A test using node-geocode module",
"main": "index.js",
"scripts": {
"test": "node index"
"test": "node test/index"
},

@@ -9,0 +9,0 @@ "repository": {

@@ -13,2 +13,40 @@ # address-to-geocode

## Example
```js
// My Location
var myLocation = "New York";
// Handler to output data
var handler = function (err, location) {
if (err) { throw err; }
console.log(location);
};
require("../index")
(myLocation, handler)
("Paris", handler)
;
```
## Documentation
### `AddressToGeocode(address, callback)`
Converts a string representing an address to geocode data.
#### Params:
* **String** *address* The searched location
* **Function** *callback* The callback function
#### Return:
* **Object** AddressToGeocode function
### `AddressToGeocode.handleLocation(guess)`
A function that handles the location. This can be overriden creating your own handler.
#### Params:
* **Array** *guess* Locations returned by Geocoder
#### Return:
* **Object** An object containing `lat` and `lng` fields.
## How to contribute

@@ -15,0 +53,0 @@