Repository navigation
Expand file tree
/
Copy pathgeocoding.py
More file actions
54 lines (38 loc) · 1.46 KB
/
Copy pathgeocoding.py
File metadata and controls
54 lines (38 loc) · 1.46 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
import common
import convert
# TODO(mdr-eng): test unicode parameters (e.g. in addresses).
def geocode(ctx, address=None, components=None, bounds=None, region=None, language=None):
"""
Geocoding is the process of converting addresses
(like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic
coordinates (like latitude 37.423021 and longitude -122.083739), which you
can use to place markers or position the map.
"""
params = {}
if address:
params["address"] = address
if components:
params["components"] = convert.components(components)
if bounds:
params["bounds"] = convert.bounds(bounds)
if region:
params["region"] = region
if language:
params["language"] = language
return common._get(ctx, "/maps/api/geocode/json", params)["results"]
def reverse_geocode(ctx, latlng, result_type=None, location_type=None, language=None):
"""
Reverse geocoding is the process of converting geographic coordinates into a
human-readable address.
"""
# TODO(mdr-eng): Add ReST style doc comments.
params = {
"latlng": convert.latlng(latlng)
}
if result_type:
params["result_type"] = convert.join_list("|", result_type)
if location_type:
params["location_type"] = convert.join_list("|", location_type)
if language:
params["language"] = language
return common._get(ctx, "/maps/api/geocode/json", params)["results"]