diff --git a/lib/google-places.js b/lib/google-places.js index 2c4a5e7..1127100 100644 --- a/lib/google-places.js +++ b/lib/google-places.js @@ -26,28 +26,40 @@ var GooglePlaces = function(key, options) { return this; }; -//Google place search + + +// Google place search GooglePlaces.prototype.search = function(options, cb) { - options = _.defaults(options, { - location: [42.3577990, -71.0536364], - radius: 10, - sensor: false, - language: 'en', - rankby: 'prominence', - types: [] - }); - - options.location = options.location.join(','); - - if (options.types.length > 0) { - options.types = options.types.join('|'); - } else { - delete options.types; - } - if (options.rankby == 'distance') - options.radius = null; - - this._doRequest(this._generateUrl(options, 'search'), cb); + this.searchRequest('search', options, cb); +}; + +// Google place nearbySearch +GooglePlaces.prototype.nearbySearch = function(options, cb) { + this.searchRequest('nearbysearch', options, cb); +}; + +// Handle building general - search api request +GooglePlaces.prototype.searchRequest = function(type, options, cb) { + options = _.defaults(options, { + location: [42.3577990, -71.0536364], + radius: 10, + sensor: false, + language: 'en', + rankby: 'prominence', + types: [] + }); + + options.location = options.location.join(','); + + if (options.types.length > 0) { + options.types = options.types.join('|'); + } else { + delete options.types; + } + if (options.rankby == 'distance') + options.radius = null; + + this._doRequest(this._generateUrl(options, type), cb); }; GooglePlaces.prototype.autocomplete = function(options, cb) { @@ -59,10 +71,19 @@ GooglePlaces.prototype.autocomplete = function(options, cb) { this._doRequest(this._generateUrl(options, 'autocomplete'), cb); }; -// Goolge place details +// Google place photo +GooglePlaces.prototype.photo = function(options, cb) { + // Set default max height or max width if not exist + if (!options.maxHeight && !options.maxWidth){ + options.maxHeight = 400; + } + + this._doRequest(this._generateUrl(options, 'photo'), cb); +}; + +// Google place details GooglePlaces.prototype.details = function(options, cb) { options = _.defaults(options, { - reference: options.reference, sensor: false, language: 'en' });