简体   繁体   English

如何在 Google Maps API 中获取所选国家/地区的所有城市或乡镇

[英]How to get all cities or townships of selected country in Google Maps API

As I found currently I can get nearby locations of selected region in Google Place API.正如我目前发现的,我可以在 Google Place API 中获取所选区域的附近位置。 I like to know how can I get all townships/distinct of selected region in Google Maps or Places API?我想知道如何在 Google Maps 或 Places API 中获取所选区域的所有城镇/地区?

You can use a code similar to the following to restrict the search to a certain country.您可以使用类似于以下内容的代码将搜索限制在某个国家/地区。

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&key=your-key"></script>
    <label for="city">
         <input id="city" name="city">
    </label>

    <script>
        var input = document.getElementById('city');
        var options = {
          types: ['(cities)'],
          componentRestrictions: {country: "us"}
         };
        var searchBox = new google.maps.places.SearchBox(input,options);
    </script>

More codes can be found here更多代码可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM