Skip to content
Snippets Groups Projects

Update Locations.ipynb

Closed dsdesai2 requested to merge patch-6 into master
1 file
+ 2
2
Compare changes
  • Side-by-side
  • Inline
+ 2
2
%% Cell type:markdown id: tags:
<img src="https://news.illinois.edu/files/6367/543635/116641.jpg" alt="University of Illinois" style="width: 200px;"/>
## Dictionaries ##
By Richard Sowers
* <r-sowers@illinois.edu>
* <https://publish.illinois.edu/r-sowers/>
Copyright 2020 University of Illinois Board of Trustees. All Rights Reserved.
Licensed under the MIT license
%% Cell type:markdown id: tags:
This notebook is part of the 2020 "ISE Freshman" effort
%% Cell type:markdown id: tags:
### imports ###
%% Cell type:code id: tags:
``` python
import json
import urllib.request
import urllib.parse
```
%% Cell type:markdown id: tags:
### constants ###
%% Cell type:code id: tags:
``` python
API="AIzaSyC-xrpJidt-7G9mrwBeky6OS_r6BGw_0pE"
```
%% Cell type:code id: tags:
``` python
data={
"Richard Sowers": {"Born":"Silver Spring, Maryland","High School":"Newport Beach, CA"}
"Dhilan Desai": {"Born":"Cleveland, Ohio","High School":"Wheaton, IL"}
}
#TASK: I would like everyone to enter their own data in this dictionary.
```
%% Cell type:code id: tags:
``` python
print(urllib.parse.quote_plus("Silver Spring, Maryland"))
```
%% Output
Silver+Spring%2C+Maryland
%% Cell type:code id: tags:
``` python
url="https://maps.googleapis.com/maps/api/geocode/json?address=Silver+Spring%2C+Maryland&key=AIzaSyA8i0_S1UuJrBMHAIACVHE5HAhikWO51Sk"
url="https://maps.googleapis.com/maps/api/geocode/json?address=Cleveland%2C+Ohio&key=AIzaSyA8i0_S1UuJrBMHAIACVHE5HAhikWO51Sk"
```
%% Cell type:code id: tags:
``` python
with urllib.request.urlopen(url) as response:
out=response.read()
print(out)
json_out=json.loads(out)
print("\n\n")
print(json_out)
print("\n\n")
print(json_out["results"])
```
%% Output
b'{\n "results" : [\n {\n "address_components" : [\n {\n "long_name" : "Silver Spring",\n "short_name" : "Silver Spring",\n "types" : [ "locality", "political" ]\n },\n {\n "long_name" : "13",\n "short_name" : "13",\n "types" : [ "administrative_area_level_3", "political" ]\n },\n {\n "long_name" : "Montgomery County",\n "short_name" : "Montgomery County",\n "types" : [ "administrative_area_level_2", "political" ]\n },\n {\n "long_name" : "Maryland",\n "short_name" : "MD",\n "types" : [ "administrative_area_level_1", "political" ]\n },\n {\n "long_name" : "United States",\n "short_name" : "US",\n "types" : [ "country", "political" ]\n }\n ],\n "formatted_address" : "Silver Spring, MD, USA",\n "geometry" : {\n "bounds" : {\n "northeast" : {\n "lat" : 39.037769,\n "lng" : -76.971717\n },\n "southwest" : {\n "lat" : 38.9796481,\n "lng" : -77.0639719\n }\n },\n "location" : {\n "lat" : 38.99066570000001,\n "lng" : -77.026088\n },\n "location_type" : "APPROXIMATE",\n "viewport" : {\n "northeast" : {\n "lat" : 39.037769,\n "lng" : -76.971717\n },\n "southwest" : {\n "lat" : 38.9796481,\n "lng" : -77.0639719\n }\n }\n },\n "place_id" : "ChIJJ-lqZk7Pt4kR35qyZagzhAA",\n "types" : [ "locality", "political" ]\n }\n ],\n "status" : "OK"\n}\n'
{'results': [{'address_components': [{'long_name': 'Silver Spring', 'short_name': 'Silver Spring', 'types': ['locality', 'political']}, {'long_name': '13', 'short_name': '13', 'types': ['administrative_area_level_3', 'political']}, {'long_name': 'Montgomery County', 'short_name': 'Montgomery County', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'Maryland', 'short_name': 'MD', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'formatted_address': 'Silver Spring, MD, USA', 'geometry': {'bounds': {'northeast': {'lat': 39.037769, 'lng': -76.971717}, 'southwest': {'lat': 38.9796481, 'lng': -77.0639719}}, 'location': {'lat': 38.99066570000001, 'lng': -77.026088}, 'location_type': 'APPROXIMATE', 'viewport': {'northeast': {'lat': 39.037769, 'lng': -76.971717}, 'southwest': {'lat': 38.9796481, 'lng': -77.0639719}}}, 'place_id': 'ChIJJ-lqZk7Pt4kR35qyZagzhAA', 'types': ['locality', 'political']}], 'status': 'OK'}
[{'address_components': [{'long_name': 'Silver Spring', 'short_name': 'Silver Spring', 'types': ['locality', 'political']}, {'long_name': '13', 'short_name': '13', 'types': ['administrative_area_level_3', 'political']}, {'long_name': 'Montgomery County', 'short_name': 'Montgomery County', 'types': ['administrative_area_level_2', 'political']}, {'long_name': 'Maryland', 'short_name': 'MD', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'United States', 'short_name': 'US', 'types': ['country', 'political']}], 'formatted_address': 'Silver Spring, MD, USA', 'geometry': {'bounds': {'northeast': {'lat': 39.037769, 'lng': -76.971717}, 'southwest': {'lat': 38.9796481, 'lng': -77.0639719}}, 'location': {'lat': 38.99066570000001, 'lng': -77.026088}, 'location_type': 'APPROXIMATE', 'viewport': {'northeast': {'lat': 39.037769, 'lng': -76.971717}, 'southwest': {'lat': 38.9796481, 'lng': -77.0639719}}}, 'place_id': 'ChIJJ-lqZk7Pt4kR35qyZagzhAA', 'types': ['locality', 'political']}]
%% Cell type:code id: tags:
``` python
#TASK: complete this function:
def get_lat_lng(place):
#get lat and lng using above
return {"lat":lat,"lng":lng}
```
%% Cell type:code id: tags:
``` python
```
Loading