Repository navigation
Expand file tree
/
Copy pathgoogleMapsSearch.py
More file actions
125 lines (100 loc) · 4.34 KB
/
Copy pathgoogleMapsSearch.py
File metadata and controls
125 lines (100 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import googlemaps
from googleplaces import GooglePlaces, types, lang
from geopy.distance import vincenty, great_circle
from googlemaps import convert
import math
import pyrebase
import requests
config = {
"apiKey": "AIzaSyAFjbldaX_ZJw_yOLahlYJNFtlBbxP8hTg",
"authDomain": "ngcode-9f40c.firebaseapp.com",
"databaseURL": "https://ngcode-9f40c.firebaseio.com",
"storageBucket": "ngcode-9f40c.appspot.com"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
gmaps = googlemaps.Client(key='AIzaSyBgFJr6eJK7QgPRMX205_Cv2QsCiKZZUnI')
def get_locals(lat, lng):
YOUR_API_KEY = 'AIzaSyBgFJr6eJK7QgPRMX205_Cv2QsCiKZZUnI'
base = "http://maps.googleapis.com/maps/api/geocode/json?"
latlng = {}
latlng['lat'] = lat
latlng['lng'] = lng
destination = gmaps.reverse_geocode(latlng)
street_name = destination[0]['address_components'][1]['long_name']
print(street_name)
google_places = GooglePlaces(YOUR_API_KEY)
stores = [types.TYPE_HARDWARE_STORE,
types.TYPE_CONVENIENCE_STORE,
types.TYPE_GROCERY_OR_SUPERMARKET] # types.TYPE_SHOPPING_MALL,
store_result = google_places.nearby_search(lat_lng=latlng,
radius=5000, types=stores)
gas_result = google_places.nearby_search(lat_lng=latlng, name='gas',
radius=5000, types=types.TYPE_GAS_STATION)
police_result = google_places.nearby_search(lat_lng=latlng, name='police',
radius=5000, types=types.TYPE_POLICE)
fireStation_result = google_places.nearby_search(lat_lng=latlng, name='fire dept. station',
radius=5000, types=types.TYPE_FIRE_STATION)
for place in store_result.places:
# Returned places from a query are place summaries.
geo = place.geo_location
geo_lat = float(geo['lat'])
geo_lng = float(geo['lng'])
geo = (geo_lat, geo_lng)
data ={'name': place.name, 'geo': geo}
print(place.geo_location)
db.child(street_name).child("locals").child('stores').push(data)
for place in gas_result.places:
# Returned places from a query are place summaries.
geo = place.geo_location
geo_lat = float(geo['lat'])
geo_lng = float(geo['lng'])
geo = (geo_lat, geo_lng)
data = {'name': place.name, 'geo': geo}
print(place.geo_location)
db.child(street_name).child("locals").child('gas').push(data)
for place in police_result.places:
# Returned places from a query are place summaries.
geo = place.geo_location
geo_lat = float(geo['lat'])
geo_lng = float(geo['lng'])
geo = (geo_lat, geo_lng)
data = {'name': place.name, 'geo': geo}
print(place.geo_location)
db.child(street_name).child("locals").child('police').push(data)
for place in fireStation_result.places:
# Returned places from a query are place summaries.
geo = place.geo_location
geo_lat = float(geo['lat'])
geo_lng = float(geo['lng'])
geo = (geo_lat, geo_lng)
data = {'name': place.name, 'geo': geo}
print(place.geo_location)
db.child(street_name).child("locals").child('fire stations').push(data)
if store_result.has_attributions:
print(store_result.html_attributions)
for place in store_result.places:
# Returned places from a query are place summaries.
print(place.name)
print(place.geo_location)
print(place.place_id + "\n")
geo1 = store_result.places[0].geo_location
geo1_lat = float(geo1['lat'])
geo1_lng = float(geo1['lng'])
geo2 = store_result.places[1].geo_location
geo2_lat = float(geo2['lat'])
geo2_lng = float(geo2['lng'])
radius = 6371 * 1000
dlat = math.radians(geo2_lat - geo1_lat)
dlon = math.radians(geo2_lng - geo1_lng)
a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(geo1_lat)) \
* math.cos(math.radians(geo2_lat)) * math.sin(dlon / 2) * math.sin(
dlon / 2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
d = radius * c
if d < 4000:
print("gucci $$$$")
return street_name
if __name__ == "__main__":
loc = get_locals(33.893229, -118.374267)
print("hi")