Add geo point

This commit is contained in:
Ritchie Martori 2013-06-24 15:22:25 -07:00
parent 88f634df38
commit 93e749c722
3 changed files with 26 additions and 2 deletions

View File

@ -701,7 +701,7 @@ Asteroid Model's with a GeoPoint property and an attached DataSource may be quer
Find the 3 nearest coffee shops. Find the 3 nearest coffee shops.
CoffeeShop.attach(oracle); CoffeeShop.attachTo(oracle);
var here = new GeoPoint({lat: 10.32424, long: 5.84978}); var here = new GeoPoint({lat: 10.32424, long: 5.84978});
CoffeeShop.find({where: {location: {near: here}}}, function(err, nearbyShops) { CoffeeShop.find({where: {location: {near: here}}}, function(err, nearbyShops) {
console.info(nearbyShops); // [CoffeeShop, ...] console.info(nearbyShops); // [CoffeeShop, ...]

View File

@ -10,3 +10,9 @@ var asteroid = module.exports = require('./lib/asteroid');
asteroid.Connector = require('./lib/connectors/base-connector'); asteroid.Connector = require('./lib/connectors/base-connector');
asteroid.Memory = require('./lib/connectors/memory'); asteroid.Memory = require('./lib/connectors/memory');
/**
* Types
*/
asteroid.GeoPoint = require('./lib/geo-point');

18
lib/geo-point.js Normal file
View File

@ -0,0 +1,18 @@
/**
* Export the `GeoPoint` class.
*/
module.exports = GeoPoint;
function GeoPoint(data) {
if(!(this instanceof GeoPoint)) {
return new GeoPoint(data);
}
this.lat = data.lat;
this.long = data.long || data.lng;
}
// TODO remove this
// register the type
require('jugglingdb/lib/model-builder').ModelBuilder.registerType(GeoPoint);