How to use the googlemaps.convert function in googlemaps

To help you get started, we’ve selected a few googlemaps examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googlemaps / google-maps-services-python / test / test_convert.py View on Github external
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)
github googlemaps / google-maps-services-python / googlemaps / places.py View on Github external
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)
github googlemaps / google-maps-services-python / googlemaps / elevation.py View on Github external
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", [])
github googlemaps / google-maps-services-python / googlemaps / roads.py View on Github external
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", [])