Yinxing commited on
Commit
70697c8
·
verified ·
1 Parent(s): 3eb9674

Upload func.py

Browse files
Files changed (1) hide show
  1. func.py +36 -0
func.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from geopy.geocoders import Nominatim
2
+ from geopy import geocoders
3
+ from geopy.distance import geodesic
4
+ import pandas as pd
5
+ import streamlit as st
6
+
7
+
8
+
9
+ def find_nearby_places(lat, lon, place_type, radius):
10
+ geolocator = Nominatim(user_agent="nearby_search")
11
+ location = geolocator.reverse((lat, lon))
12
+ st.write(f"\n検索した場所: {location}\n")
13
+
14
+ query = f"{place_type} near {lat}, {lon}"
15
+ df = []
16
+ try:
17
+ places = geolocator.geocode(query, exactly_one=False, limit=None)
18
+ if places:
19
+ for place in places:
20
+ place_coords = (place.latitude, place.longitude)
21
+ place_distance = geodesic((lat, lon), place_coords).kilometers
22
+ if place_distance <= radius:
23
+ df.append((place,) + place_coords + (place_distance,))
24
+ #print(f"{place.address} ({place_distance:.2f} km)")
25
+ else:
26
+ st.write("No nearby places found for the given type.")
27
+ except:
28
+ st.write("Error: Unable to fetch nearby places.")
29
+
30
+ return pd.DataFrame(df, columns = ['場所', 'lat', 'lon', '距離(km)'])
31
+
32
+
33
+ def get_place(x):
34
+ loc = Nominatim(user_agent="GetLoc")
35
+ getLoc = loc.geocode(x,country_codes='jp')
36
+ return getLoc.latitude, getLoc.longitude, getLoc