EMS.Service.Suggest

Suggest service is used to take a small fragment of text and suggest an address.  This might be used for auto completion fields or such things.

The service has a single method EMS.Service.Suggest.suggest which uses a callback function.

function(response, status) {
}
response{Object} is a wrapper around the suggestions.
status{EMS.Status} is the response status.  Any other response other than EMS.Status.OK indicates some sort of error.  You can consult the response.message for more information.

Response

{
    suggestions[]:{
        text: {String},
        id:   {String}
    }
}
Summary
EMS.Service.SuggestSuggest service is used to take a small fragment of text and suggest an address.
Constructor
EMS.Service.Suggest
Functions
suggest

Constructor

EMS.Service.Suggest

Functions

suggest

suggest: function(query,
callback)

Basic Example

var service = new EMS.Service.Suggest();
service.suggest("Mel", function(response, status) {
    if (status == EMS.Status.OK) {
        for (var i = 0; i < response.suggestions.length; i++) {
            // Do something with the response
            var text = response.suggestions[i].text;
            var id   = response.suggestions[i].id;
        }
    } else {
        // Error status
        alert(response.message);
    }
});

Complex Example

var query = {
    text: "Be",                             // Actual text to search for
    size: 10,                               // Maximum number of items to get back
    granularity: [EMS.Granularity.SUBURB,   // Array of the types of items to return
                  EMS.Granularity.REGION]
}
service.suggest(query, function(response, status) {
    if (status == EMS.Status.OK) {
        for (var i = 0; i < response.suggestions.length; i++) {
            // Do something with the response
            var text = response.suggestions[i].text;
            var id   = response.suggestions[i].id;
        }
    } else {
        // Error status
        alert(response.message);
    }
});

Parameters

query{Mixed} is either a {String} or a query as an {Object} is actual item to find.
callback{Function} is the callback function in the form function(result, status).
suggest: function(query,
callback)
The request was processed perfectly.
Close