파이썬은 강력하다. 지도 관련된 서비스를 하려면 필수적으로 GeoPy 정도는 있어야 대부분 구현이 가능하다. 먼저 홈페이지 방문해서 예제를 보면서 파악하는 것이 급선무!
https://geopy.readthedocs.io/en/stable/#module-geopy.geocoders
Welcome to GeoPy’s documentation! — GeoPy 2.3.0 documentation
Different services have different Terms of Use, quotas, pricing, geodatabases and so on. For example, Nominatim is free, but provides low request limits. If you need to make more queries, consider using another (probably paid) service, such as OpenMapQuest
geopy.readthedocs.io
Installation
pip install geopy
사용 예
To geolocate a query to an address and coordinates: 주소 문자열로 위도, 경도 좌표 구해오기
>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim(user_agent="specify_your_app_name_here")
>>> location = geolocator.geocode("175 5th Avenue NYC")
>>> print(location.address)
Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, ...
>>> print((location.latitude, location.longitude))
(40.7410861, -73.9896297241625)
>>> print(location.raw)
{'place_id': '9167009604', 'type': 'attraction', ...}
To find the address corresponding to a set of coordinates:
반대의 경우, 위도/경도 값으로 주소를 역으로 가져오는 방법
>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim(user_agent="specify_your_app_name_here")
>>> location = geolocator.reverse("52.509669, 13.376294")
>>> print(location.address)
Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union
>>> print((location.latitude, location.longitude))
(52.5094982, 13.3765983)
>>> print(location.raw)
{'place_id': '654513', 'osm_type': 'node', ...}
일다 여기까지.
홈페이지에서는 이것이 서비스가 아니라, 함수가 들어오면 요청해서 결과를 알려주는 것이라고 분명히 밝히고 잇다.

'IT > 파이썬' 카테고리의 다른 글
파이썬 슬라이스 join 을 이용해서 주소 문자열 만들기 (0) | 2023.05.09 |
---|---|
Django manage.py my_command - 커스텀 명령어 만들기 (0) | 2023.05.05 |
Python - UnicodeDecodeError: 'cp949' 에러 해결 방법 (0) | 2023.05.04 |
Django ORM - aggregation sum 결과가 0 인 결과 배제하기 (0) | 2023.05.04 |
Django ORM - Group by 사용해서 Count, Sum, Avg 구하기 (0) | 2023.05.03 |