2121
2222
2323@functools .lru_cache ()
24- def get_place_coords (place_type : str , latitude : float , longitude : float , search_radius_km : int , keyfn : Path ) -> pandas .DataFrame :
24+ def get_place_coords (
25+ place_type : str , latitude : float , longitude : float , search_radius_km : int , keyfn : Path
26+ ) -> pandas .DataFrame :
2527 """
2628 Get places using Google Maps Places API
2729 Requires you to have a Google Cloud account with API key.
@@ -43,7 +45,10 @@ def get_place_coords(place_type: str, latitude: float, longitude: float, search_
4345
4446 place_json = r .json ()["results" ]
4547
46- places = pandas .DataFrame (index = [p ["name" ] for p in place_json ], columns = ["latitude" , "longitude" , "distance_km" , "vicinity" ])
48+ places = pandas .DataFrame (
49+ index = [p ["name" ] for p in place_json ],
50+ columns = ["latitude" , "longitude" , "distance_km" , "vicinity" ],
51+ )
4752 places ["latitude" ] = [p ["geometry" ]["location" ]["lat" ] for p in place_json ]
4853 places ["longitude" ] = [p ["geometry" ]["location" ]["lng" ] for p in place_json ]
4954 places ["vicinity" ] = [p ["vicinity" ] for p in place_json ]
@@ -53,13 +58,20 @@ def get_place_coords(place_type: str, latitude: float, longitude: float, search_
5358
5459if __name__ == "__main__" :
5560 p = ArgumentParser ()
56- p .add_argument ("place_type" , help = "Place type to search: https://developers.google.com/places/supported_types" )
57- p .add_argument ("searchloc" , help = "initial latituude, longitude to search from" , nargs = 2 , type = float )
61+ p .add_argument (
62+ "place_type" ,
63+ help = "Place type to search: https://developers.google.com/places/supported_types" ,
64+ )
65+ p .add_argument (
66+ "searchloc" , help = "initial latituude, longitude to search from" , nargs = 2 , type = float
67+ )
5868 p .add_argument ("radius" , help = "search radius (kilometers)" , type = int )
5969 p .add_argument ("refloc" , help = "reference location (lat, lon)" , nargs = 2 , type = float )
6070 p .add_argument ("-k" , "--keyfn" , help = "Google Places API key file" , default = "~/googlemaps.key" )
6171 a = p .parse_args ()
6272
6373 place_coords = get_place_coords (a .place_type , * a .searchloc , a .radius , a .keyfn )
6474
65- place_coords ["distance_km" ] = vdist (place_coords ["latitude" ], place_coords ["longitude" ], * a .refloc )[0 ] / 1e3
75+ place_coords ["distance_km" ] = (
76+ vdist (place_coords ["latitude" ], place_coords ["longitude" ], * a .refloc )[0 ] / 1e3
77+ )
0 commit comments