fuzzy-state-search
v0.1.0
Published
Get the U.S. state closest to the user's location.
Downloads
6
Readme
Get the U.S. state closest to the user's position. Compares lat/lon coordinates from a Position
object to the centroid of each U.S. state. Favors speed over accuracy.
Locations near a state's border may return an incorrect, neighboring state. If accuracy is important, you should use a third-party reverse geocoding API (e.g. Google's).
Installation
First install node.js. Then:
npm install fuzzy-state-search --save
Usage
Require the module and pass it a Position
object:
var getState = require('fuzzy-state-search');
function logState( pos ){
var state = getState( pos );
console.log( 'User lives in ' + state );
};
// Get their coordinates using the HTML5 geolocation API.
navigator.geolocation.getCurrentPosition( logState );
Contributing
Please read the Contributing guidelines.
Running Tests
We are using nodeunit to test. To run tests, first install nodeunit and any dependencies via npm:
npm install
Run tests with:
npm test