简体   繁体   中英

How can I get all possible addresses with lat and long by city or district prefix?

I want to implement code like below:

When I send request to endpoint with name of " Sig " (just an example),I need it to give me

[

 {
  "name ":"Sighisoara",
  "lat":"smth",
  "Long":"smth"

 },

 {
  "name ":"Sigulda",
  "lat":"smth",
  "Long":"smth"
 }
]

Currently, I use OpenStreetMap , It has no such functionality. To get a address, you should write exactly how the address is spelled. For example, to get Sighisoara , you need to write Sighisoara Any idea to do that or free api which provides such functionality.

PS, I am using Python.

I think the point is for you to understand the structure of this dictionary that contains all the city names,and you can try to split the structures. For example, I got a dictionary of weather from an API here, and I want to print out the current temperature.

weather ={'coord': {'lon': 113.25, 'lat': 23.1167}, 'weather': [{'id': 803, 'main': 'Clouds', 'description': 'broken clouds', 'icon': '04d'}], 'base': 'stations', 'main': {'temp': 298.18, 'feels_like': 298.31, 'temp_min': 295.37, 'temp_max': 299.82, 'pressure': 1018, 'humidity': 53}, 'visibility': 6000, 'wind': {'speed': 2, 'deg': 160}, 'clouds': {'all': 75}, 'dt': 1615355271, 'sys': {'type': 1, 'id': 9620, 'country': 'CN', 'sunrise': 1615329655, 'sunset': 1615372438}, 'timezone': 28800, 'id': 1809858, 'name': 'Guangzhou', 'cod': 200} This is the code I will use: current_temp = (weather['main']['temp']) The name of this dictionary is weather, inside of it, there are several lists of 'main', which contained the 'temp' I want. So you can make sure if your code is correctly catch the structure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM