-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnearbyplace.py
63 lines (34 loc) · 1.18 KB
/
nearbyplace.py
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
import requests
import pprint
from flask import Flask, request, jsonify
import json
app = Flask(__name__)
place_api="your_api"
def location_data():
type="police"
r=requests.get("https://maps.googleapis.com/maps/api/place/search/json?location=31.6607795,74.8214579&rankby=distance&types=police&sensor=false&key="+place_api)
#print r.content
#d = ast.literal_eval(r)
result = json.loads(r.text)
data=dict(result)
#pprint.pprint(data)
result=data["results"]
final_data=dict()
final_data["data"]=list()
for item in result:
print "Name" , item["name"]
print "Address" ,item["vicinity"]
print "Co-ordinates", item["geometry"]["location"]["lat"], item["geometry"]["location"]["lng"]
print "********************************"
d= {}
d["name"]=item["name"]
d["address"]=item["vicinity"]
d["lat"]=item["geometry"]["location"]["lat"]
d["lng"]=item["geometry"]["location"]["lng"]
final_data["data"].append(d)
return final_data
@app.route('/')
def data():
return jsonify(location_data())
if __name__ == "__main__":
app.run(debug=True, port =80)