Skip to content

Commit

Permalink
adding examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Oliveira committed Mar 12, 2011
1 parent 5370b09 commit 87b0888
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 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);
30 changes: 30 additions & 0 deletions 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']);
});
30 changes: 30 additions & 0 deletions 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);
// });


0 comments on commit 87b0888

Please sign in to comment.