[ Whereis® API Home ] [ Developers' Guide ] [ JS Services ]
The Address Validation service provides the capability to determine the accuracy of an address, to correct an erroneous address, and to report the types of adjustments that were required.
To validate an address, perform the following steps.
- Initialise the Validation service.
- Format the request.
- Submit the request, nominating a callback function.
If the request succeeds, the API returns a list of Validation objects (a Geocode object with an array of Adjustment Types).
4. Process the response within the callback function.
A successful request returns a list of results. In some cases the list may be empty or may contain only one result at index[0]. Each response object will include adjustments and a geocode, which contains coordinates and the address for the location.
The following code snippet performs a validation and retrieves the first usable result.
//Initialise service
var service = new EMS.Service.Validation();
//Format request
var query = "55 Lonsdale Street, Melbourne";
//Submit request
service.validate(query, callback);
//Handle the response
function callback (response, status){
// Check the status of the result is non-error
if (status == EMS.Status.OK) {
// Success! check the results
var items = response.results;
if (items.length > 0) {
var msg = items[0].toString();
alert(msg);
} else {
// Found nothing
}
} else {
// Error! Display the message.
alert(response.message);
}
};
Full details of request and response object parameters are set out in the JSON API.
There is also an appendix of Address Adjustment Types