Skip to content

Commit 04d3541

Browse files
committed
changes geocode api -now it works with postcodes
1 parent d31c203 commit 04d3541

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# View crime statistics in the UK!
22
A flask powered app, with data visualisation using D3.
3+
4+
![ScreenShot](ScreenShot.png)

ScreenShot.png

272 KB
Loading

src/templates/home.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<body class="body">
99
<h1>Welcome to the UK Crime Stats site</h1>
1010
<form action="{{ url_for('viewcrime') }}" method ='POST'>
11-
<input type= 'text' name='location' placeholder='Enter a UK address' id = 'location'>
11+
<input type= 'text' name='location' placeholder='Enter a UK postcode' id = 'location'>
1212
<button type="submit" id="submit_button" class="button-styling">Get stats</button>
1313
</form>
1414
</body>

src/views.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,11 @@ def home():
4141

4242

4343
def get_data(location):
44-
KEY = read_json('params.json', 'MAPQ')
45-
url1 = 'http://open.mapquestapi.com/geocoding/v1/address?'
46-
params1 = dict(
47-
key=KEY,
48-
location=location
49-
)
50-
resp1 = requests.get(url=url1, params=params1)
51-
ll = json.loads(resp1.text)['results'][0]['locations'][0]['displayLatLng']
52-
latitude = ll['lat']
53-
longitude = ll['lng']
44+
url_postcode = "http://api.postcodes.io/postcodes/"+location
45+
resp_postcode = requests.get(url=url_postcode)
46+
ll = json.loads(resp_postcode.text)['result']
47+
latitude = ll['latitude']
48+
longitude = ll['longitude']
5449
url = 'https://data.police.uk/api/crimes-street/all-crime?'
5550
params = dict(
5651
lat=latitude,

0 commit comments

Comments
 (0)