Skip to content

Instantly share code, notes, and snippets.

@chanced
Created October 2, 2011 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chanced/1257719 to your computer and use it in GitHub Desktop.
Save chanced/1257719 to your computer and use it in GitHub Desktop.
require('./db_connect');
var geocoder = require('geocoder');
var cs = require('../cyberstride/mongoose');
var AddressSchema = new Schema({
name : {type: String, default : ''},
street1 : {type: String, default : ''},
street2 : {type: String, default : ''},
city : {type: String, default : '', required: true},
state : {type: String, required : true},
zip : {type: String, default : ''},
country : {type: String},
location : {lng: Number, lat:Number},
type : {type: String, enum:['agent', 'agency', 'registrant'], index:true},
primary : {type: Boolean, default: false}
});
var Address = mongoose.model('Address', AddressSchema);
Address.prototype.geocode = function(cb){
geocoder.geocode(this.full, cb, function(err, data){
var rloc = data.results[0].geometry.location;
this.location = {lng: rloc.lng, lat: rloc.lat};
cb(err,data);
})
}
module.exports = Address;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment