geo

0.0.3 • Public • Published

Geo for Node.js

by Felipe Oliveira (http://twitter.com/_felipera)

Geo is a very basic, but simple, geo library for Node.js using Google's Geocode API (V3) for Geocoding and GeoHash for GeoSpatial support.

Installation

	npm install geo

Usage - Geocode

	var geo = require('geo');
	
	var address = '885 6th Ave #15D New York, NY 10001';
	var sensor = false;
	geo.geocoder(geo.google, address, sensor, function(formattedAddress, latitude, longitude) {
		console.log("Formatted Address: " + formattedAddress);
		console.log("Latitude: " + latitude);
		console.log("Longitude: " + longitude);
	});

Usage - GeoHash

	// First define a model instance
	var model = {'address': '885 6th #15D, New York, NY 10001', 'baths': '1', 'beds': '1'};

	// Define callback that gets the location (from a single field, multiple fields, whatever) from the model instance (model can be anything, DB class, JSON, array)
	var locationGetterCallback = function(model) { return model['address']; };

	// Define callback that will augment the model instance with geo information such as latitude, longitude and geohash
	var geoSetterCallback = function(model, latitude, longitude, hash, callback) { 
		console.log('Geo Hash: ' + hash); 
		model['latitude'] = latitude; 
		model['longitude'] = longitude; 
		model['geohash'] = hash; 
		callback( model ); 
	};

	// Now let's see what happens with the model
	geo.geomodel(model, locationGetterCallback, geoSetterCallback, function(model) {
		console.log("Model: " + model['address'] + ', Geo: ' + model['geohash']);
	}); 

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    8
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    8
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i geo

Weekly Downloads

7

Version

0.0.3

License

none

Last publish

Collaborators

  • felipera