2

私は google.maps.places.Autocomplete を使用しています。都市をオートコンプリートしたいのですが、オートコンプリートの結果を Google ドキュメントのように 1 つだけでなく、複数の都市に制限します。

これは私が持っているものです

<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places" type="text/javascript"></script>
<script type="text/javascript">
 function initialize() {

    var input = document.getElementById('searchTextField');

    /* restrict to multiple cities? */
    var options = {
       types: ['(cities)'],
       componentRestrictions: {country: "us", "fr"}
    };


    var autocomplete = new google.maps.places.Autocomplete(input, options);
 }
 google.maps.event.addDomListener(window, 'load', initialize);
</script>

<div>
<input id="searchTextField" type="text" size="50" placeholder="Enter a location" autocomplete="on">
</div>
4

3 に答える 3

3

実際には、Places API は制限として 1 つの国のみをサポートしています。コンポーネントの制限

于 2012-08-16T10:38:17.217 に答える
1

私はグーグルプレイスオートコンプリートに不慣れですが、エラーはここにあると思います:

componentRestrictions: {country: "us", "fr"}

これを試して:

componentRestrictions: {country: ["us", "fr"]}
于 2012-05-04T19:32:54.583 に答える
0

制限のために追加できる国は 1 つだけです。 https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions

于 2015-03-17T21:03:02.680 に答える