所以我有这个在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',
],
],
];
答案 0 :(得分:1)
快速搜索产生了这个:
https://raw.githubusercontent.com/David-Haim/CountriesToCitiesJSON/master/countriesToCities.json
http://www.geobytes.com/free-ajax-cities-jsonp-api/
首先应该没有基本用途。不要认为它有状态。在这种情况下可能想要使用第二个API