关于javascript:如何使用Google Map API V3选择所有城市

how to select all cities using google map api v3

我认为一种可能的方法是:

1
2
3
4
service.search({
    types: ["city"],
    bounds: founded_bounds
}, function(places, status) {});
  • 使用常规的Geocoder服务选择国家/州范围
  • 提出地点搜寻要求
  • 但是可用的场所类型中没有"城市"类型。 如何获得选定国家/地区的所有城市?

    UPD
    感谢bweaver,地点<=>城市

    但是现在我又遇到了麻烦:
    谷歌地图的地方搜索工作实在荒唐! 我做了一点演示来显示问题。 我也将其发布到google api bugtracker。

    1
    2
    3
    *see console F12
    Search for places in Hawaii (all types): 21
    Search for places in Honolulu (all types): 22

    这是不真实的。


    我找到了解决方案。 它不属于google map api,但是可以正常工作(formatted = true是可选的)

  • http://ws.geonames.org/countryInfoJSON?country=US&formatted=true
    重要数据:" geonameId":6252001
  • 为geonameId做递归搜索(我认为深度3-4级就足够了)http://ws.geonames.org/childrenJSON?geonameId=6252001&style=full&maxRows=1000&formatted=true
  • 通过" fclName"参数过滤结果具有" city,vilage"子字符串的结果
  • 使用这个逻辑,我将为每个状态创建脚本生成的json文件。 这个脚本每个月都会作为cron工作

    如果有人知道如何使用Google Map API进行此类任务-请发布!