-
Notifications
You must be signed in to change notification settings - Fork 7
/
geocoder.js
46 lines (40 loc) · 1.28 KB
/
geocoder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var geocoder = Npm.require('node-geocoder');
// backwards compatibility
if (typeof Meteor.wrapAsync === "undefined") {
Meteor.wrapAsync = Meteor._wrapAsync;
}
GeoCoder = function geoCoderConstructor(options) {
var self = this;
self.options = _.extend({
geocoderProvider: 'google',
httpAdapter: 'http'
}, options || {});
};
var gc = function (address, options, callback) {
var g = geocoder(options.geocoderProvider, options.httpAdapter, options);
g.geocode(address, callback);
};
GeoCoder.prototype.geocode = function geoCoderGeocode(address, callback) {
if (callback) {
callback = Meteor.bindEnvironment(callback, function (error) {
if (error) throw error;
});
gc(address, this.options, callback);
} else {
return Meteor.wrapAsync(gc)(address, this.options);
}
};
var rv = function (lat, lng, options, callback) {
var g = geocoder(options.geocoderProvider, options.httpAdapter, options);
g.reverse({lat: lat, lon: lng}, callback);
};
GeoCoder.prototype.reverse = function geoCoderReverse(lat, lng, callback) {
if (callback) {
callback = Meteor.bindEnvironment(callback, function (error) {
if (error) throw error;
});
rv(lat, lng, this.options, callback);
} else {
return Meteor.wrapAsync(rv)(lat, lng, this.options);
}
};