Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 63 lines (41 sloc) 2.232 kB
7ec406e changing the name to geo i didnt realize theres a geonode already on npm
U-HBO\foliveir authored
1 # Geo for Node.js
647ed8f format readme
Felipe Oliveira authored
2 by Felipe Oliveira (http://twitter.com/_felipera)
8a8f3e0 initial import
Felipe Oliveira authored
3
2c7bfc4 adding geohash support to augment model instances
Felipe Oliveira authored
4 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.
8a8f3e0 initial import
Felipe Oliveira authored
5
d19dbc7 @feliperazeek add installation to the README
authored
6
7
8 ## Installation
9
10 npm install geo
11
12
13
2c7bfc4 adding geohash support to augment model instances
Felipe Oliveira authored
14 ## Usage - Geocode
8a8f3e0 initial import
Felipe Oliveira authored
15
d19dbc7 @feliperazeek add installation to the README
authored
16 var geo = require('geo');
c70baed format readme
Felipe Oliveira authored
17
18 var address = '885 6th Ave #15D New York, NY 10001';
19 var sensor = false;
7ec406e changing the name to geo i didnt realize theres a geonode already on npm
U-HBO\foliveir authored
20 geo.geocoder(geo.google, address, sensor, function(formattedAddress, latitude, longitude) {
c70baed format readme
Felipe Oliveira authored
21 console.log("Formatted Address: " + formattedAddress);
22 console.log("Latitude: " + latitude);
23 console.log("Longitude: " + longitude);
24 });
2c7bfc4 adding geohash support to augment model instances
Felipe Oliveira authored
25
748f4e6 @eckardt added support for reverse geocoding
eckardt authored
26 // Reverse Geocoding also works
27 var latlong = { 'latitude': 52.5112, 'longitude': 13.45155};
28 geo.geocoder(geo.google, latlong, sensor, function(formattedAddress, latitude, longitude) {
29 console.log("Formatted Address: " + formattedAddress);
30 console.log("Latitude: " + latitude);
31 console.log("Longitude: " + longitude);
32 });
2c7bfc4 adding geohash support to augment model instances
Felipe Oliveira authored
33
34 ## Usage - GeoHash
35
36 // First define a model instance
37 var model = {'address': '885 6th #15D, New York, NY 10001', 'baths': '1', 'beds': '1'};
38
39 // 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)
40 var locationGetterCallback = function(model) { return model['address']; };
41
42 // Define callback that will augment the model instance with geo information such as latitude, longitude and geohash
43 var geoSetterCallback = function(model, latitude, longitude, hash, callback) {
44 console.log('Geo Hash: ' + hash);
45 model['latitude'] = latitude;
46 model['longitude'] = longitude;
47 model['geohash'] = hash;
48 callback( model );
49 };
50
51 // Now let's see what happens with the model
52 geo.geomodel(model, locationGetterCallback, geoSetterCallback, function(model) {
53 console.log("Model: " + model['address'] + ', Geo: ' + model['geohash']);
54 });
55
56
57
58 ## More Information on GeoHash
59
60 1. See it in action at http://openlocation.org/geohash/geohash-js/.
61
5370b09 adding info to readme
Felipe Oliveira authored
62 2. Go understand how it works at http://en.wikipedia.org/wiki/Geohash and http://hitching.net/2009/11/10/scalable-fast-accurate-geo-apps-using-google-app-engine-geohash-faultline-correction/.
Something went wrong with that request. Please try again.