Last active
April 13, 2022 11:18
-
-
Save louisebolden/3cb1db65888aae87bde99fd53226e28d to your computer and use it in GitHub Desktop.
Get a JSON array of cities and countries from Teleport.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.get('https://api.teleport.org/api/countries/').then(function(data) { | |
var countries = $.map(data['_links']['country:items'], function(country) { return country.name }); | |
fetchedCities = []; | |
countries.forEach(function(country) { | |
$.get('https://api.teleport.org/api/cities/?search=' + country + '&embed=city%3Asearch-results%2Fcity%3Aitem%2Fcity').then(function(data) { | |
var cities = data['_embedded']['city:search-results']; | |
cities.forEach(function(city) { | |
var city = { | |
country: country, | |
fullName: city['_embedded']['city:item'].full_name, | |
name: city['_embedded']['city:item'].name, | |
population: city['_embedded']['city:item'].population | |
} | |
fetchedCities.push(city); | |
}); | |
console.log(fetchedCities); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment