Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions dist/angularjs-google-places.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion src/angularjs-google-places.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ provider('ngGPlacesAPI', function () {
sensor: false,
latitude: null,
longitude: null,
types: ['food'],
// types: ['food'],
map: null,
elem: null,
textSearchKeys: ['formatted_address', 'geometry', 'html_attributions','icon','id','name',
'opening_hours', 'rating','reference','types', 'vicinity'],
nearbySearchKeys: ['name', 'reference', 'vicinity'],
placeDetailsKeys: ['formatted_address', 'formatted_phone_number',
'reference', 'website'
],
textSearchErr: 'Unable to find by text',
nearbySearchErr: 'Unable to find nearby places',
placeDetailsErr: 'Unable to find place details',
_textSearchApiFnCall: 'textSearch',
_nearbySearchApiFnCall: 'nearbySearch',
_placeDetailsApiFnCall: 'getDetails'
};
Expand All @@ -38,6 +42,19 @@ provider('ngGPlacesAPI', function () {
return pResp;
};

var parseTSJSON = function (response) {
var pResp = [];
var keys = defaults.textSearchKeys;
response.map(function (result) {
var obj = {};
angular.forEach(keys, function (k) {
obj[k] = result[k];
});
pResp.push(obj);
});
return pResp;
};

var parsePDJSON = function (response) {
var pResp = {};
var keys = defaults.placeDetailsKeys;
Expand Down Expand Up @@ -88,6 +105,13 @@ provider('ngGPlacesAPI', function () {
args._apiFnCall = defaults._nearbySearchApiFnCall;
return commonAPI(args);
},
textSearch: function(args) {
args._genLocation = true;
args._errorMsg = defaults.textSearchErr;
args._parser = parseTSJSON;
args._apiFnCall = defaults._textSearchApiFnCall;
return commonAPI(args);
},
placeDetails: function (args) {
args._errorMsg = defaults.placeDetailsErr;
args._parser = parsePDJSON;
Expand Down
32 changes: 29 additions & 3 deletions test/angularjs-google-places.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
describe('Service: ngGPlacesAPI', function () {
var ngGPlacesAPI, $rootScope;

beforeEach(module('ngGPlaces', 'mockedNearbySearch',
beforeEach(module('ngGPlaces', 'mockedNearbySearch','mockedTextSearch',
'mockedPlaceDetails', function ($provide, ngGPlacesAPIProvider,
defaultNSJSON, defaultPDJSON) {
defaultNSJSON, defaultPDJSON, defaultTSJSON) {
$provide.value('gPlaces', {
PlacesService: function () {
this.nearbySearch = function (req, cb) {
Expand All @@ -14,6 +14,9 @@ describe('Service: ngGPlacesAPI', function () {
this.getDetails = function (req, cb) {
cb(defaultPDJSON, true);
};
this.textSearch = function (req, cb) {
cb(defaultTSJSON, true);
};
},
PlacesServiceStatus: {
'OK': true
Expand Down Expand Up @@ -65,6 +68,29 @@ describe('Service: ngGPlacesAPI', function () {
});
});

describe('Text Search', function () {
beforeEach(inject(function (_ngGPlacesAPI_, _$rootScope_) {
ngGPlacesAPI = _ngGPlacesAPI_;
$rootScope = _$rootScope_;
}));

it('should return places for a location searched by text', function () {
var results = ngGPlacesAPI.textSearch({
latitude: -33.8665433,
longitude: 151.1956316,
radius: 10,
query: 'city name'
}).then(function (data) {
results = data;
});
$rootScope.$apply();
expect(results.length).toEqual(19);
expect(results[0].name).not.toBeUndefined();
expect(results[1].vicinity).not.toBeUndefined();
expect(results[2].reference).not.toBeUndefined();
});
});

describe('Place Details Search', function () {
beforeEach(inject(function (_ngGPlacesAPI_, _$rootScope_) {
ngGPlacesAPI = _ngGPlacesAPI_;
Expand Down Expand Up @@ -105,4 +131,4 @@ describe('Service: ngGPlacesAPI', function () {
});
});

});
});
Loading