Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用API使google地址自动填充,以数字和街道替换完整地址?_Javascript_Html_Api_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 如何使用API使google地址自动填充,以数字和街道替换完整地址?

Javascript 如何使用API使google地址自动填充,以数字和街道替换完整地址?,javascript,html,api,google-maps,google-maps-api-3,Javascript,Html,Api,Google Maps,Google Maps Api 3,我正在使用谷歌API自动填写地址表。现在我找到了填充完整地址的代码,它自动填充图片链接1中的所有字段,如图所示。我已隐藏街道编号和路线字段,因为它们不需要 我要找的是,在我选择地址后,我希望我输入的地址栏不在该栏中显示城市、州和国家。我希望自动填充看起来像图片链接2中所示,其中地址字段仅用数字和街道替换完整地址,而不包括城市、州和国家。键入时,我选择了图片链接3中显示的地址,它会自动填充图片链接2中显示的内容 有人知道在点击地址后如何用数字和街道替换完整地址吗?我在此链接中使用了html和jsc

我正在使用谷歌API自动填写地址表。现在我找到了填充完整地址的代码,它自动填充图片链接1中的所有字段,如图所示。我已隐藏街道编号和路线字段,因为它们不需要

我要找的是,在我选择地址后,我希望我输入的地址栏不在该栏中显示城市、州和国家。我希望自动填充看起来像图片链接2中所示,其中地址字段仅用数字和街道替换完整地址,而不包括城市、州和国家。键入时,我选择了图片链接3中显示的地址,它会自动填充图片链接2中显示的内容

有人知道在点击地址后如何用数字和街道替换完整地址吗?我在此链接中使用了html和jscript:

图片链接1:

图片链接2:

图片链接3:

尝试修改fillInAddress,如下所示:

function fillInAddress() {
  // Get the place details from the autocomplete object.
  var place = autocomplete.getPlace();

  for (var component in componentForm) {
    document.getElementById(component).value = '';
    document.getElementById(component).disabled = false;
  }

  // Get each component of the address from the place details
  // and fill the corresponding field on the form.
  var streetAddress = '';
  for (var i = 0; i < place.address_components.length; i++) {
    var addressType = place.address_components[i].types[0];
    if (componentForm[addressType]) {

      if (addressType === 'street_number') {
        streetAddress += place.address_components[i][componentForm[addressType]];
      } else if (addressType === 'route') {
        if (streetAddress.length) {
          streetAddress += ' ';
        }
        streetAddress += place.address_components[i][componentForm[addressType]];
      }

      var val = place.address_components[i][componentForm[addressType]];
      document.getElementById(addressType).value = val;
      document.getElementById('autocomplete').value = streetAddress;
    }
  }
}
基于


希望这有帮助

很高兴听到,也很乐意帮忙!: