Skip to content

Instantly share code, notes, and snippets.

@janisblaus
Created January 13, 2015 19:24
Show Gist options
  • Save janisblaus/67abdbe86955b4606c95 to your computer and use it in GitHub Desktop.
Save janisblaus/67abdbe86955b4606c95 to your computer and use it in GitHub Desktop.
$(".ui-autocomplete-city").autocomplete({
source: function(request, response){
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term,
username: 'netcore',
country: 'lv'
},
success: function(data) {
response($.map(data.geonames, function(item) {
return {
label: item.name + ((item.adminName1 && item.adminName1 != item.name) ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.name + ((item.adminName1 && item.adminName1 != item.name) ? ", " + item.adminName1 : "")
}
}));
}
});
},
minLength: 2,
select: function(event, ui) {
console.log(ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment