📅  最后修改于: 2023-12-03 15:26:36.360000             🧑  作者: Mango
这是一个能够查找五角大楼地区的程序,它可以通过输入相关信息来返回符合条件的位置坐标。
该程序使用 Python 语言编写,需要安装相应的依赖库如 geopy 和 folium。具体使用方法如下:
pip install geopy folium
python search_pentagon.py
以下是程序的主要代码片段,详细代码请参见 Github 仓库。
import folium
from geopy.geocoders import Nominatim
def search_location(address):
geolocator = Nominatim(user_agent='search_pentagon')
location = geolocator.geocode(address)
return location.latitude, location.longitude
def search_pentagon():
address = input("Please enter the address or keyword: ")
location = search_location(address)
# Search for pentagon area within a radius of 2KM
pentagon = (38.8719, -77.0563)
map_ = folium.Map(location=pentagon, zoom_start=12)
folium.Marker(pentagon, tooltip='Pentagon').add_to(map_)
folium.Circle(
location=pentagon,
radius=2000,
color='crimson',
fill=True,
fill_color='crimson',
opacity=0.3
).add_to(map_)
point = (location[0], location[1])
folium.Marker(
location=point,
tooltip=address,
icon=folium.Icon(color='blue', icon='map-marker')
).add_to(map_)
# Check if the searched location is within pentagon
distance = geodesic(point, pentagon).meters
if distance <= 2000:
print(f"The location is {distance:.2f} meters away from the pentagon.")
else:
print(f"The location is {distance:.2f} meters away from the pentagon.")
print("Sorry, the location you searched is not within the pentagon area.")
if __name__ == '__main__':
search_pentagon()