forked from wyattdanger/geocoder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
93 lines (66 loc) · 1.45 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Geocoder
*/
/**
* Module Dependencies
*/
/**
* Version
*/
var version = '0.2.0';
/**
* Geocoder
*/
function Geocoder () {
this.selectProvider("google");
};
/**
* Geocoder prototype
*/
Geocoder.prototype = {
/**
* Selects a webservice provider
*
* @param {String} name, required
* @param {Object} opts, optional
* @api public
*/
selectProvider: function ( name, opts ) {
if ( ! name ) {
return cbk( new Error( "Geocoder.selectProvider requires a name.") );
}
this.provider = name;
this.providerOpts = opts || {};
this.providerObj = require("./providers/"+name);
},
/**
* Request geocoordinates of given `loc` from Google
*
* @param {String} loc, required
* @param {Function} cbk, required
* @param {Object} opts, optional
* @api public
*/
geocode: function ( loc, cbk, opts ) {
if ( ! loc ) {
return cbk( new Error( "Geocoder.geocode requires a location.") );
}
return this.providerObj.geocode(this.providerOpts, loc, cbk, opts);
},
reverseGeocode: function ( lat, lng, cbk, opts ) {
if ( !lat || !lng ) {
return cbk( new Error( "Geocoder.reverseGeocode requires a latitude and longitude." ) );
}
return this.providerObj.reverseGeocode(this.providerOpts, lat, lng, cbk, opts );
},
/**
* Return Geocoder version
*
* @api public
*/
version: version
};
/**
* Export
*/
module.exports = new Geocoder();