Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding examples

  • Loading branch information...
commit 87b08889d4199f8c5651c0f2b0d1767c92c0df41 1 parent 5370b09
Felipe Oliveira authored
View
19 app.js
@@ -0,0 +1,19 @@
+var Connect = require('connect'),
+ quip = require('quip'),
+ dispatch = require('dispatch');
+
+var geo = require('geo');
+
+var server = Connect.createServer(
+ quip(),
+ dispatch({
+ '/': function(req, res, next){
+ res.text('hello world!');
+ },
+ '/geo': function(req, res, next){
+ res.json({hello: 'world'});
+ }
+ })
+);
+
+server.listen(8080);
View
30 examples/geohash_model.js
@@ -0,0 +1,30 @@
+// *********************************************
+// *********************************************
+// Geo by Felipe Oliveira
+// March 2011
+// http://geeks.aretotally.in/projects/geo
+// http://twitter.com/_felipera
+// *********************************************
+// *********************************************
+
+var geo = require('../lib/geo');
+
+// 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']);
+});
View
30 examples/simple_geocode_lookup.js
@@ -0,0 +1,30 @@
+// *********************************************
+// *********************************************
+// Geo by Felipe Oliveira
+// March 2011
+// http://geeks.aretotally.in/projects/geo
+// http://twitter.com/_felipera
+// *********************************************
+// *********************************************
+
+var geo = require('../lib/geo');
+
+// Good Address
+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);
+});
+
+// Bad Address
+// var address = '1111 Foobar Ave #15D New York, NY 9999';
+// 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);
+// });
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.