I'm using Bing's Autosuggest UI(Without Map) to populate an autocomplete in an address input, but depending on the query, the selectedResult
is missing either an adminDistrict
or a postalCode
.
The code below is very similar to the one used on Bing's demo. The only difference is in the innerHTML
of selectedSuggestion()
.
Two examples of addresses for which information is missing are the following:
1) 242 W 16th St, New York, NY - missing adminDistrict;
2) 227 W Trade St, Charlotte, NC - missing zipCode.
Any ideas on how to resolve this issue, so that every selectedResult
contains an adminDistrict
and a zipCode
?
Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest', {
callback: onLoad,
errorCallback: onError,
credentials: 'Your Bing Maps Key'
});
function onLoad() {
var options = {maxResults: 5};
var manager = new Microsoft.Maps.AutosuggestManager(options);
manager.attachAutosuggest('#searchBox', '#searchBoxContainer', selectedSuggestion);
}
function onError(message) {
document.getElementById('printoutPanel').innerHTML = message;
}
function selectedSuggestion(suggestionResult) {
document.getElementById('printoutPanel').innerHTML =
'Suggestion: ' + suggestionResult.formattedSuggestion +
'<br> Street: ' + suggestionResult.address.addressLine +
'<br> City: ' + suggestionResult.address.locality +
'<br> State: ' + suggestionResult.address.adminDistrict +
'<br> Zip: ' + suggestionResult.address.postalCode;
}