Address Autocomplete with JSON webservice
This service returns a list of placenames for a given postalcode. The result is using the JSON format to overcome the problems with loading xml data from an other server. It is thus possible to use the geonames server for this placename lookup within webpages served by your own server.
See also: GeoNames webservices · all webservices on one table · Postal code search · the countries with postal codes
Placename Lookup with Postal Code (JSON)
Parameters
- postalcode - the full postal code
- country - ISO 3166 country code
- maxRows - the maximal numbers of rows returned, optional parameter with a default value of 10
- callback - optional parameter to specifiy the name of the javascript function to be wrapped around the datastructure
Result
An array of postalcodes objects, with the attributes placeName, countryCode and postalcode.
Example
Use your own account in your application, not the demo account of the example.
An autocomplete for a postal code
A form with a country list and a postal code field calls the service as soon as the visitor leaves the field: when the postal code has one place the place field is filled in at once, when several places use the same postal code (6600 in Austria, for example) the form shows a suggest box to choose from, and 2161 is a code with one place.
The page calls the service with a callback function: the service wraps its answer in the call of that function, which browsers allow across servers - this is what the callback parameter is for. Preselect the visitor's country if you know it, and link to www.geonames.org when you use the service.