Add geo point
This commit is contained in:
parent
88f634df38
commit
93e749c722
|
@ -701,7 +701,7 @@ Asteroid Model's with a GeoPoint property and an attached DataSource may be quer
|
|||
|
||||
Find the 3 nearest coffee shops.
|
||||
|
||||
CoffeeShop.attach(oracle);
|
||||
CoffeeShop.attachTo(oracle);
|
||||
var here = new GeoPoint({lat: 10.32424, long: 5.84978});
|
||||
CoffeeShop.find({where: {location: {near: here}}}, function(err, nearbyShops) {
|
||||
console.info(nearbyShops); // [CoffeeShop, ...]
|
||||
|
|
6
index.js
6
index.js
|
@ -10,3 +10,9 @@ var asteroid = module.exports = require('./lib/asteroid');
|
|||
|
||||
asteroid.Connector = require('./lib/connectors/base-connector');
|
||||
asteroid.Memory = require('./lib/connectors/memory');
|
||||
|
||||
/**
|
||||
* Types
|
||||
*/
|
||||
|
||||
asteroid.GeoPoint = require('./lib/geo-point');
|
|
@ -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);
|
Loading…
Reference in New Issue