Replies: 4 comments
-
Hey @Olfdev, I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this together! To access the latitude and longitude of a city using the API, you can cross-reference the city ID from the API response with the Here's a basic example of how you might implement this in code: import json
# Load the JSON data from the file
with open('countries+cities.json', 'r') as file:
data = json.load(file)
# Function to get latitude and longitude by city ID
def get_lat_long(city_id):
for city in data:
if city['id'] == city_id:
return city['latitude'], city['longitude']
return None
# Example usage
city_id = 2398 # Example city ID for Manchester
lat_long = get_lat_long(city_id)
if lat_long:
print(f"Latitude: {lat_long[0]}, Longitude: {lat_long[1]}")
else:
print("City ID not found.") This code assumes you have the Additionally, there is ongoing work to include latitude and longitude in the API responses directly, but it's not yet implemented [2]. |
Beta Was this translation helpful? Give feedback.
-
Could a human being help please? Because I don't have any countries+cities.json file to crosscheck anything with so that answer is not really helpful. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@Olfdev That's purposely not included in the response due to server resources limitations. However, I have added them within this endpoint of getting cities by state and country. https://api.countrystatecity.in/v1/countries/[ciso]/states/[siso]/cities |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for the answer, I'll check it out. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm a bit confused. In the documentation, there is a part on Country details to get translations and other things. But I don't find anything to get the city details and I need the lat and long of cities.
I see they exist in the countries+cities.json but I don't find how to access it using the API.
Using only https://api.countrystatecity.in/v1/countries/[ciso]/cities returns only city name and id.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions