-
-
Save mmalecki/1257752 to your computer and use it in GitHub Desktop.
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
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){ | |
var self = this; | |
geocoder.geocode(self.full, cb, function(err, data){ | |
var rloc = data.results[0].geometry.location; | |
self.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