3

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;
}
Zach Newburgh
  • 563
  • 3
  • 11

1 Answers1

1

Autosuggest is meant to aid with geocoding results. The primary goal of geocoding is to find the coordinate for displaying an address in the right location on a map. Anything else is extra and not guaranteed to be returned. A geocoder is not an address validation tool.

That said, I'm a bit surprised that the adminDistrict isn't returned. Not returning a zip code could be for a large number of reason.

rbrundritt
  • 16,570
  • 2
  • 21
  • 46
  • 1
    Thanks, @rbrundritt, for the explanation. Does Bing have a tool that would validate the address? – Zach Newburgh Apr 27 '17 at 13:00
  • No. true address validation services are only really available in a small number of countries are usually fairly expensive. May companies often use geocoders as a cheap alternative, but it isn't 100% perfect. – rbrundritt Apr 27 '17 at 16:08