gpt4 book ai didi

javascript - 美国城市/州数组的简单方法

转载 作者:行者123 更新时间:2023-12-03 09:29:05 24 4
gpt4 key购买 nike

所以我有这个网络应用程序,它在 JavaScript 中使用这个位置选择变量。我想知道是否有一种简单的方法可以为美国进行转换/执行此操作,而无需输入每个州和城市。

  var location_selectors = {"country":["Australia"],"state":{"Australia":["Australian Capital Territory","New South Wales","Northern Territory","Queensland","South Australia","Tasmania","Victoria","Western Australia"]},"city":{"Australian Capital Territory":["Canberra"],"New South Wales":["Sydney","Albury","Armidale","Bathurst","Broken Hill","Cessnock","Coffs Harbour","Dubbo","Gosford","Goulburn","Grafton","Griffith","Lake Macquarie","Lismore","Maitland","Newcastle","Nowra","Orange","Port Macquarie","Queanbeyan","Tamworth","Tweed Heads","Wagga Wagga","Wollongong","Wyong"],"Northern Territory":["Darwin","Alice Springs","Katherine","Palmerston"],"Queensland":["Brisbane","Bundaberg","Cairns","Charters Towers","Gladstone","Gold Coast","Gympie","Hervey Bay","Ipswich","Logan City","Mackay","Maryborough","Mount Isa","Nambour","Redcliffe","Rockhampton","Sunshine Coast","Thuringowa","Toowoomba","Townsville"],"South Australia":["Adelaide","Mount Gambier","Murray Bridge","Port Augusta","Port Pirie","Port Lincoln","Victor Harbor","Whyalla"],"Tasmania":["Hobart","Burnie","Clarence","Devonport","Glenorchy","Launceston"],"Victoria":["Melbourne","Benalla","Ballarat","Bendigo","Geelong","Latrobe City","Mildura","Shepparton","Swan     Hill","Wangaratta","Warrnambool","Wodonga"],"Western Australia":    ["Perth","Albany","Broome","Bunbury","Geraldton","Fremantle","Kalgoorlie","Mandu    rah","Port Hedland"]}};

这是 php 版本

$location_selectors = [
'country' => [
'Australia',
],
'state' => [
'Australia' => [
'Australian Capital Territory',
'New South Wales',
'Northern Territory',
'Queensland',
'South Australia',
'Tasmania',
'Victoria',
'Western Australia',
],
],
'city' => [
'Australian Capital Territory' => [
'Canberra',
],
'New South Wales' => [
'Sydney',
'Albury',
'Armidale',
'Bathurst',
'Broken Hill',
'Cessnock',
'Coffs Harbour',
'Dubbo',
'Gosford',
'Goulburn',
'Grafton',
'Griffith',
'Lake Macquarie',
'Lismore',
'Maitland',
'Newcastle',
'Nowra',
'Orange',
'Port Macquarie',
'Queanbeyan',
'Tamworth',
'Tweed Heads',
'Wagga Wagga',
'Wollongong',
'Wyong',
],
'Northern Territory' => [
'Darwin',
'Alice Springs',
'Katherine',
'Palmerston',
],
'Queensland' => [
'Brisbane',
'Bundaberg',
'Cairns',
'Charters Towers',
'Gladstone',
'Gold Coast',
'Gympie',
'Hervey Bay',
'Ipswich',
'Logan City',
'Mackay',
'Maryborough',
'Mount Isa',
'Nambour',
'Redcliffe',
'Rockhampton',
'Sunshine Coast',
'Thuringowa',
'Toowoomba',
'Townsville',
],
'South Australia' => [
'Adelaide',
'Mount Gambier',
'Murray Bridge',
'Port Augusta',
'Port Pirie',
'Port Lincoln',
'Victor Harbor',
'Whyalla',
],
'Tasmania' => [
'Hobart',
'Burnie',
'Clarence',
'Devonport',
'Glenorchy',
'Launceston',
],
'Victoria' => [
'Melbourne',
'Benalla',
'Ballarat',
'Bendigo',
'Geelong',
'Latrobe City',
'Mildura',
'Shepparton',
'Swan Hill',
'Wangaratta',
'Warrnambool',
'Wodonga',
],
'Western Australia' => [
'Perth',
'Albany',
'Broome',
'Bunbury',
'Geraldton',
'Fremantle',
'Kalgoorlie',
'Mandurah',
'Port Hedland',
],
],

];

最佳答案

快速搜索得到了这个:

https://raw.githubusercontent.com/David-Haim/CountriesToCitiesJSON/master/countriesToCities.json

http://www.geobytes.com/free-ajax-cities-jsonp-api/

第一个应该适合基本使用。但不要认为它有状态。在这种情况下可能需要使用第二个 API

关于javascript - 美国城市/州数组的简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31572061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com