From b87b7c85c0eb0dabd431163f52c2f7b12602e6a6 Mon Sep 17 00:00:00 2001 From: okland Date: Thu, 20 Nov 2014 17:49:50 +0200 Subject: [PATCH 1/2] Added google place search nearby + google places get place photo --- lib/google-places.js | 66 +++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/lib/google-places.js b/lib/google-places.js index 2c4a5e7..0905990 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,7 +71,17 @@ 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.marginHeight = 400; + } + + this._doRequest(this._generateUrl(options, 'photo'), cb); +}; + +// Google place details GooglePlaces.prototype.details = function(options, cb) { options = _.defaults(options, { reference: options.reference, From 3026bf85e2e0270ea733fd57a801f381ec597ea0 Mon Sep 17 00:00:00 2001 From: okland Date: Fri, 21 Nov 2014 10:01:29 +0200 Subject: [PATCH 2/2] minor fix --- lib/google-places.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/google-places.js b/lib/google-places.js index 0905990..1127100 100644 --- a/lib/google-places.js +++ b/lib/google-places.js @@ -75,7 +75,7 @@ GooglePlaces.prototype.autocomplete = function(options, cb) { GooglePlaces.prototype.photo = function(options, cb) { // Set default max height or max width if not exist if (!options.maxHeight && !options.maxWidth){ - options.marginHeight = 400; + options.maxHeight = 400; } this._doRequest(this._generateUrl(options, 'photo'), cb); @@ -84,7 +84,6 @@ GooglePlaces.prototype.photo = function(options, cb) { // Google place details GooglePlaces.prototype.details = function(options, cb) { options = _.defaults(options, { - reference: options.reference, sensor: false, language: 'en' });