Hi I am Using jquery UI autocomplete plugin for zipcode field.
jQuery UI autocomplete plugin uses geonames.org's JSON response.
Here is my code to get response :-
jQuery( "#"+prefix+"_zip" ).autocomplete({
source: function( request, response ) {
jQuery.ajax({
url: "http://ws.geonames.org/postalCodeSearchJSON",
dataType: "jsonp",
data: {
style: "full",
maxRows: 12,
postalcode_startsWith: request.term
},
success: function( data ) {
response( jQuery.map( data.postalCodes, function( item ) {
return {
label: item.placeName + (item.adminCode1 ? ", " + item.adminCode1 : "") + ", " + item.postalCode + ", "+item.countryCode,
value: item.postalCode
}
}));
jQuery('.ui-autocomplete').css('width', '188px');
}
});
}
For now, when put my cursor in zipcode field and enter any zipcode then it suggest me a autocomplete list for entered no or we can say jQuery plugin shows me relative values for the code that I have Entered.
Now I have one custom requirement, I want to get JSON response for US zipcodes only.
I mean when enter any value in zipcode field then it should show US related zipcode as autocomplete list.
Can any one tell me that how to get only US zipcodes JSON response from geonames.org ??
Your url can pass the country as a parameter,
e.g. Mexico http://ws.geonames.org/searchJSON?&country=MX
United States http://ws.geonames.org/searchJSON?&country=US
Something also cool is if you want to have the api return all cities in Mexico and the United states you can do this,
http://ws.geonames.org/searchJSON?&country=US,MX&username=tpassolano
NOTE: geonames now requires a username, updated api call
Hope this helps!