Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Felipe Oliveira
committed
Mar 12, 2011
1 parent
5370b09
commit 87b0888
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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']); | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); | |||
// }); | |||
|
|||
|