Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 44 additions & 23 deletions lib/google-places.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'
});
Expand Down