Skip to content

Instantly share code, notes, and snippets.

@unkleara
Created November 24, 2013 11:53
Show Gist options
  • Save unkleara/7626371 to your computer and use it in GitHub Desktop.
Save unkleara/7626371 to your computer and use it in GitHub Desktop.
geobytes service angularjs and lodash
app.factory('geoData', ['$http', '$q', 'limitToFilter', function ($http, $q, limitToFilter) {
return {
get: function(inputValue) {
var url = "http://gd.geobytes.com/AutoCompleteCity?callback=JSON_CALLBACK &filter=US&q=";
//since $http.get returns a promise,
//and promise.then() also returns a promise
//that resolves to whatever value is returned in it's
//callback argument, we can return that.
return $http.jsonp(url + inputValue)
.then(function (result) {
return limitToFilter(_.map(result.data, function(v) {
return v.replace(', United States','')}), 10);
});
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment