From 0a1855b766e86f168e4dfbb167704423dd6b7d6b Mon Sep 17 00:00:00 2001 From: Wojciech Marusarz Date: Tue, 6 Oct 2015 17:57:44 +0200 Subject: [PATCH] Fixed issue #7: parseNSJSON method don't read keys from options always use defaults. Now 'req' object which extends 'defautls' about user configuration is passed to parseNSJSON and parsePDJSON functions, so valid fields 'nearbySearchKeys' and 'placeDetailsKeys' are used to parse JSON and return what user requested" --- dist/angularjs-google-places.min.js | 3 +-- src/angularjs-google-places.js | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dist/angularjs-google-places.min.js b/dist/angularjs-google-places.min.js index 2cdb8e4..38c334b 100644 --- a/dist/angularjs-google-places.min.js +++ b/dist/angularjs-google-places.min.js @@ -1,2 +1 @@ -/*! angularjs-google-places 25-09-2013 */ -"use strict";angular.module("ngGPlaces",[]),angular.module("ngGPlaces").value("gPlaces",google.maps.places),angular.module("ngGPlaces").value("gMaps",google.maps),angular.module("ngGPlaces").provider("ngGPlacesAPI",function(){var a={radius:1e3,sensor:!1,latitude:null,longitude:null,types:["food"],map:null,elem:null,nearbySearchKeys:["name","reference","vicinity"],placeDetailsKeys:["formatted_address","formatted_phone_number","reference","website"],nearbySearchErr:"Unable to find nearby places",placeDetailsErr:"Unable to find place details",_nearbySearchApiFnCall:"nearbySearch",_placeDetailsApiFnCall:"getDetails"},b=function(b){var c=[],d=a.nearbySearchKeys;return b.map(function(a){var b={};angular.forEach(d,function(c){b[c]=a[c]}),c.push(b)}),c},c=function(b){var c={},d=a.placeDetailsKeys;return angular.forEach(d,function(a){c[a]=b[a]}),c};this.$get=function(d,e,f,g,h){function i(b){function c(a,b){b==g.PlacesServiceStatus.OK?d.$apply(function(){return l.resolve(i._parser(a))}):d.$apply(function(){l.reject(i._errorMsg)})}var i=angular.copy(a,{});angular.extend(i,b);var j,k,l=e.defer();return i._genLocation&&(i.location=new f.LatLng(i.latitude,i.longitude)),j=i.map?i.map:i.elem?i.elem:h.document.createElement("div"),k=new g.PlacesService(j),k[i._apiFnCall](i,c),l.promise}return{getDefaults:function(){return a},nearbySearch:function(c){return c._genLocation=!0,c._errorMsg=a.nearbySearchErr,c._parser=b,c._apiFnCall=a._nearbySearchApiFnCall,i(c)},placeDetails:function(b){return b._errorMsg=a.placeDetailsErr,b._parser=c,b._apiFnCall=a._placeDetailsApiFnCall,i(b)}}},this.$get.$inject=["$rootScope","$q","gMaps","gPlaces","$window"],this.setDefaults=function(b){angular.extend(a,b)}}); \ No newline at end of file +"use strict";angular.module("ngGPlaces",[]),angular.module("ngGPlaces").value("gPlaces",google.maps.places),angular.module("ngGPlaces").value("gMaps",google.maps),angular.module("ngGPlaces").provider("ngGPlacesAPI",function(){var e={radius:1e3,sensor:!1,latitude:null,longitude:null,types:["food"],map:null,elem:null,nearbySearchKeys:["name","reference","vicinity"],placeDetailsKeys:["formatted_address","formatted_phone_number","reference","website"],nearbySearchErr:"Unable to find nearby places",placeDetailsErr:"Unable to find place details",_nearbySearchApiFnCall:"nearbySearch",_placeDetailsApiFnCall:"getDetails"},a=function(e,a){var n=[],r=a.nearbySearchKeys;return e.map(function(e){var a={};angular.forEach(r,function(n){a[n]=e[n]}),n.push(a)}),n},n=function(e,a){var n={},r=a.placeDetailsKeys;return angular.forEach(r,function(a){n[a]=e[a]}),n};this.$get=function(r,l,t,c){function i(a){function n(e,a){return a==t.PlacesServiceStatus.OK?o.resolve(i._parser(e,i)):void o.reject(i._errorMsg)}var i=angular.copy(e,{});angular.extend(i,a);var s,u,o=r.defer();return i._genLocation&&(i.location=new l.LatLng(i.latitude,i.longitude)),s=i.map?i.map:i.elem?i.elem:c.document.createElement("div"),u=new t.PlacesService(s),u[i._apiFnCall](i,n),o.promise}return{getDefaults:function(){return e},nearbySearch:function(n){return n._genLocation=!0,n._errorMsg=e.nearbySearchErr,n._parser=a,n._apiFnCall=e._nearbySearchApiFnCall,i(n)},placeDetails:function(a){return a._errorMsg=e.placeDetailsErr,a._parser=n,a._apiFnCall=e._placeDetailsApiFnCall,i(a)}}},this.$get.$inject=["$q","gMaps","gPlaces","$window"],this.setDefaults=function(a){angular.extend(e,a)}}); \ No newline at end of file diff --git a/src/angularjs-google-places.js b/src/angularjs-google-places.js index 9a739b0..e97b5bf 100644 --- a/src/angularjs-google-places.js +++ b/src/angularjs-google-places.js @@ -25,9 +25,9 @@ provider('ngGPlacesAPI', function () { _placeDetailsApiFnCall: 'getDetails' }; - var parseNSJSON = function (response) { + var parseNSJSON = function (response, req) { var pResp = []; - var keys = defaults.nearbySearchKeys; + var keys = req.nearbySearchKeys; response.map(function (result) { var obj = {}; angular.forEach(keys, function (k) { @@ -38,9 +38,9 @@ provider('ngGPlacesAPI', function () { return pResp; }; - var parsePDJSON = function (response) { + var parsePDJSON = function (response, req) { var pResp = {}; - var keys = defaults.placeDetailsKeys; + var keys = req.placeDetailsKeys; angular.forEach(keys, function (k) { pResp[k] = response[k]; }); @@ -57,7 +57,7 @@ provider('ngGPlacesAPI', function () { function callback(results, status) { if (status == gPlaces.PlacesServiceStatus.OK) { - return deferred.resolve(req._parser(results)); + return deferred.resolve(req._parser(results, req)); } else { deferred.reject(req._errorMsg); }