Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_latlng(self):
expected = "1,2"
ll = {"lat": 1, "lng": 2}
self.assertEqual(expected, convert.latlng(ll))
ll = [1, 2]
self.assertEqual(expected, convert.latlng(ll))
ll = (1, 2)
self.assertEqual(expected, convert.latlng(ll))
self.assertEqual(expected, convert.latlng(expected))
with self.assertRaises(TypeError):
convert.latlng(1)
raise ValueError(
"Valid values for the `input_type` param for "
"`find_place` are 'textquery' or 'phonenumber', "
"the given value is invalid: '%s'" % input_type
)
if fields:
invalid_fields = set(fields) - PLACES_FIND_FIELDS
if invalid_fields:
raise ValueError(
"Valid values for the `fields` param for "
"`find_place` are '%s', these given field(s) "
"are invalid: '%s'"
% ("', '".join(PLACES_FIND_FIELDS), "', '".join(invalid_fields))
)
params["fields"] = convert.join_list(",", fields)
if location_bias:
valid = ["ipbias", "point", "circle", "rectangle"]
if location_bias.split(":")[0] not in valid:
raise ValueError("location_bias should be prefixed with one of: %s" % valid)
params["locationbias"] = location_bias
if language:
params["language"] = language
return client._request("/maps/api/place/findplacefromtext/json", params)
def elevation(client, locations):
"""
Provides elevation data for locations provided on the surface of the
earth, including depth locations on the ocean floor (which return negative
values)
:param locations: List of latitude/longitude values from which you wish
to calculate elevation data.
:type locations: a single location, or a list of locations, where a
location is a string, dict, list, or tuple
:rtype: list of elevation data responses
"""
params = {"locations": convert.shortest_path(locations)}
return client._request("/maps/api/elevation/json", params).get("results", [])
def nearest_roads(client, points):
"""Find the closest road segments for each point
Takes up to 100 independent coordinates, and returns the closest road
segment for each point. The points passed do not need to be part of a
continuous path.
:param points: The points for which the nearest road segments are to be
located.
:type points: a single location, or a list of locations, where a
location is a string, dict, list, or tuple
:rtype: A list of snapped points.
"""
params = {"points": convert.location_list(points)}
return client._request("/v1/nearestRoads", params,
base_url=_ROADS_BASE_URL,
accepts_clientid=False,
extract_body=_roads_extract).get("snappedPoints", [])