使用 Bing Maps API 自动建议输入字段

问题描述

我正在尝试将自动建议功能添加到我网站上的输入字段。 我正在使用 HTML 和 JavaScript 并在 XAMPP 服务器上运行网页

我尝试了以下代码

function bingMapsReady() {
  Microsoft.Maps.loadModule("Microsoft.Maps.AutoSuggest",{
    callback: onLoad,errorCallback: logError,credentials: 'ApdwAqG2eCW7b4wN89fxAghgQSwi_jFh3HPhfVaM4MMJ63LQjemhR8YmBrx93tdX'
  });

  function onLoad() {
    var options = {
      maxResults: 8
    };
    initAutosuggestControl(options,"searchBox","searchBoxContainer");
    initAutosuggestControl(options,"searchBoxAlt","searchBoxContainerAlt");
  }
}

function initAutosuggestControl(
  options,suggestionBoxId,suggestionContainerId
) {
  var manager = new Microsoft.Maps.AutosuggestManager(options);
  manager.attachAutosuggest(
    "#" + suggestionBoxId,"#" + suggestionContainerId,selectedSuggestion
  );

  function selectedSuggestion(suggestionResult) {
    document.getElementById(suggestionBoxId).innerHTML =
      suggestionResult.formattedSuggestion;
  }
}


function logError(message) {
  console.log(message);
}
<form>

  <div class="form-group" id="searchBoxContainer ">
    <label for="searchBox" class="sr-only optional">Address 1</label>
    <input type="text" name="address_one" id="searchBox" value="" class="form-control" placeholder="Address 1">
  </div>
  <div class="form-group" id="searchBoxContainerAlt">
    <label for="searchBoxAlt" class="sr-only optional">Address 2</label>
    <input type="text" name="address_two" id="searchBoxAlt" value="" class="form-control" placeholder="Address 2">
  </div>


  <button type="submit" class="btn btn-primary">Submit</button>
</form>

上面的代码根本不起作用我检查了控制台,然后

没有任何细节或错误,有时我会收到消息

Microsoft.Maps.AutoSuggest 加载失败。

有时我什么也得不到。 有什么可以帮助解决这个问题的

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)