带有位置限制的 Google AutocompleteService 不起作用

问题描述 投票:0回答:0

我在使用带有 locationRestriction 的 AutocompleteService 时遇到问题。当我还设置 locationBias 时,该服务返回不在提供的矩形内的预测或仅返回空预测。

如何解决此问题并使 locationRestriction 与 AutocompleteService 一起正常工作?

autoCompleteService = new google.maps.places.AutocompleteService();

autoCompleteChanged() {

    const locationBias = new google.maps.LatLng(-19.454636, -44.244515);

    const rectangleBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(locationBias.lat() - 0.5, locationBias.lng() - 0.5),
      new google.maps.LatLng(locationBias.lat() + 0.5, locationBias.lng() + 0.5)
    );

    let options = {
      input: this.autoCompleteInput,
      componentRestrictions: { country: "br" },
      fields: ["address_components", "geometry"],
      types: ["address"],
      locationBias: locationBias,
      locationRestriction: rectangleBounds
    }

    this.autoCompleteService.getPlacePredictions(options, predictions => {
        console.log(predictions);
    });
  }

javascript运行示例:https://jsfiddle.net/ataufo/21kbztay/30/

google-maps google-places-api
© www.soinside.com 2019 - 2024. All rights reserved.