Google places autocomplete suggestion without country name

雨燕双飞 提交于 2021-01-27 11:23:33

问题


I am looking for a possibility to get suggestions without country name.

I have the following js code:

... var autocomplete_pickup = new google.maps.places.Autocomplete(pickup_field, {
       types: ["address"], componentRestrictions: {country: "de"}
}); ...

The result is e.g.

Bahnhofstrasse 4, Hamburg, Deutschland

Now I want to have for that example only

Bahnhofstrasse 4, Hamburg

I have limited the countries only to Germany and therefore is not necessary to show the country name.

Do you have an idea? Thanks. Heinz-Peter


回答1:


For resolve it, just add this query param &region=de into your script path

It seems like this:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=[API-KEY]&libraries=places&region=de"></script>

It helped me.



来源:https://stackoverflow.com/questions/48080596/google-places-autocomplete-suggestion-without-country-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!