コード例 #1
0
def _autocomplete(client, url_part, input_text, offset=None, location=None,
                  radius=None, language=None, types=None, components=None,
                  strict_bounds=False):
    """
    Internal handler for ``autocomplete`` and ``autocomplete_query``.
    See each method's docs for arg details.
    """

    params = {"input": input_text}

    if offset:
        params["offset"] = offset
    if location:
        params["location"] = convert.latlng(location)
    if radius:
        params["radius"] = radius
    if language:
        params["language"] = language
    if types:
        params["types"] = types
    if components:
        if len(components) != 1 or list(components.keys())[0] != "country":
            raise ValueError("Only country components are supported")
        params["components"] = convert.components(components)
    if strict_bounds:
        params["strictbounds"] = "true"

    url = "/maps/api/place/%sautocomplete/json" % url_part
    return client._request(url, params).get("predictions", [])
コード例 #2
0
def _autocomplete(client,
                  url_part,
                  input_text,
                  offset=None,
                  location=None,
                  radius=None,
                  language=None,
                  type=None,
                  components=None):
    """
    Internal handler for ``autocomplete`` and ``autocomplete_query``.
    See each method's docs for arg details.
    """

    params = {"input": input_text}

    if offset:
        params["offset"] = offset
    if location:
        params["location"] = convert.latlng(location)
    if radius:
        params["radius"] = radius
    if language:
        params["language"] = language
    if type:
        params["type"] = type
    if components:
        params["components"] = convert.components(components)

    url = "/maps/api/place/%sautocomplete/json" % url_part
    return client._get(url, params)["predictions"]
コード例 #3
0
def _autocomplete(client, url_part, input_text, offset=None, location=None,
                  radius=None, language=None, types=None, components=None,
                  strict_bounds=False):
    """
    Internal handler for ``autocomplete`` and ``autocomplete_query``.
    See each method's docs for arg details.
    """

    params = {"input": input_text}

    if offset:
        params["offset"] = offset
    if location:
        params["location"] = convert.latlng(location)
    if radius:
        params["radius"] = radius
    if language:
        params["language"] = language
    if types:
        params["types"] = types
    if components:
        params["components"] = convert.components(components)
    if strict_bounds:
        params["strictbounds"] = "true"

    url = "/maps/api/place/%sautocomplete/json" % url_part
    return client._request(url, params).get("predictions", [])
コード例 #4
0
def _autocomplete(client, url_part, input_text, session_token=None,
                  offset=None, location=None, radius=None, language=None,
                  types=None, components=None, strict_bounds=False):
    """
    Internal handler for ``autocomplete`` and ``autocomplete_query``.
    See each method's docs for arg details.
    """

    params = {"input": input_text}

    if session_token:
        params["sessiontoken"] = session_token
    if offset:
        params["offset"] = offset
    if location:
        params["location"] = convert.latlng(location)
    if radius:
        params["radius"] = radius
    if language:
        params["language"] = language
    if types:
        params["types"] = types
    if components:
        if len(components) != 1 or list(components.keys())[0] != "country":
            raise ValueError("Only country components are supported")
        params["components"] = convert.components(components)
    if strict_bounds:
        params["strictbounds"] = "true"

    url = "/maps/api/place/%sautocomplete/json" % url_part
    return client._request(url, params).get("predictions", [])
コード例 #5
0
ファイル: places.py プロジェクト: marcinmilewski1/aiogmaps
async def _autocomplete(client,
                        url_part,
                        input_text,
                        offset=None,
                        location=None,
                        radius=None,
                        language=None,
                        types=None,
                        components=None,
                        strict_bounds=False):

    params = {'input': input_text}

    if offset:
        params['offset'] = offset
    if location:
        params['location'] = convert.latlng(location)
    if radius:
        params['radius'] = radius
    if language:
        params['language'] = language
    if types:
        params['types'] = types
    if components:
        params['components'] = convert.components(components)
    if strict_bounds:
        params['strictbounds'] = 'true'

    url = '/maps/api/place/%sautocomplete/json' % url_part
    result = await client._request(url, params)
    return result['predictions']
コード例 #6
0
def geocode(client,
            address=None,
            components=None,
            bounds=None,
            region=None,
            language=None):

    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 client._request("/maps/api/geocode/json", params).get("results", [])
コード例 #7
0
def geocode(client,
            address=None,
            place_id=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.

    :param address: The address to geocode.
    :type address: string

    :param place_id: A textual identifier that uniquely identifies a place,
        returned from a Places search.
    :type place_id: string

    :param components: A component filter for which you wish to obtain a
        geocode, for example: ``{'administrative_area': 'TX','country': 'US'}``
    :type components: dict

    :param bounds: The bounding box of the viewport within which to bias geocode
        results more prominently.
    :type bounds: string or dict with northeast and southwest keys.

    :param region: The region code, specified as a ccTLD ("top-level domain")
        two-character value.
    :type region: string

    :param language: The language in which to return results.
    :type language: string

    :rtype: list of geocoding results.
    """

    params = {}

    if address:
        params["address"] = address

    if place_id:
        params["place_id"] = place_id

    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 client._request("/maps/api/geocode/json", params).get("results", [])
コード例 #8
0
    def test_components(self):
        c = {"country": "US"}
        self.assertEqual("country:US", convert.components(c))

        c = {"country": "US", "foo": 1}
        self.assertEqual("country:US|foo:1", convert.components(c))

        c = {"country": ["US", "AU"], "foo": 1}
        self.assertEqual("country:AU|country:US|foo:1", convert.components(c))

        with self.assertRaises(TypeError):
            convert.components("test")

        with self.assertRaises(TypeError):
            convert.components(1)

        with self.assertRaises(TypeError):
            convert.components(("c", "b"))
コード例 #9
0
    def test_components(self):
        c = {"country": "US"}
        self.assertEqual("country:US", convert.components(c))

        c = {"country": "US", "foo": 1}
        self.assertEqual("country:US|foo:1", convert.components(c))

        c = {"country": ["US", "AU"], "foo": 1}
        self.assertEqual("country:AU|country:US|foo:1", convert.components(c))

        with self.assertRaises(TypeError):
            convert.components("test")

        with self.assertRaises(TypeError):
            convert.components(1)

        with self.assertRaises(TypeError):
            convert.components(("c", "b"))
コード例 #10
0
ファイル: geocoding.py プロジェクト: AnkurSheel/RoutePlanner
def geocode(client, 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.

    :param address: The address to geocode.
    :type address: string

    :param components: A component filter for which you wish to obtain a geocode,
                       for example:
                       ``{'administrative_area': 'TX','country': 'US'}``
    :type components: dict

    :param bounds: The bounding box of the viewport within which to bias geocode
                   results more prominently.
    :type bounds: string or dict with northeast and southwest keys.

    :param region: The region code, specified as a ccTLD ("top-level domain")
                   two-character value.
    :type region: string

    :param language: The language in which to return results.
    :type langauge: string

    :rtype: list of geocoding results.

    """

    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 client._get("/maps/api/geocode/json", params)["results"]
コード例 #11
0
def _autocomplete(client, url_part, input_text, **params):
    """
    Internal handler for ``autocomplete`` and ``autocomplete_query``.
    See each method's docs for arg details.
    """

    params['input'] = input_text

    if 'location' in params:
        params["location"] = convert.latlng(params["location"])
    if 'components' in params:
        params["components"] = convert.components(params["components"])

    url = "/maps/api/place/%sautocomplete/json" % url_part
    return client._request(url, params)["predictions"]
コード例 #12
0
ファイル: geocoding.py プロジェクト: marcinmilewski1/aiogmaps
async def geocode(client, address=None, components=None,
                  bounds=None, region=None,
                  language=None):

    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

    result = await client._request('/maps/api/geocode/json', params)
    return result.get('results', [])
コード例 #13
0
def static_map(client,
               size,
               center=None,
               zoom=None,
               scale=None,
               format=None,
               maptype=None,
               language=None,
               region=None,
               markers=None,
               path=None,
               visible=None,
               style=None):
    """
    Downloads a map image from the Maps Static API.

    See https://developers.google.com/maps/documentation/maps-static/intro
    for more info, including more detail for each parameter below.

    :param size: Defines the rectangular dimensions of the map image.
    :type param: int or list

    :param center: Defines the center of the map, equidistant from all edges
        of the map.
    :type center: dict or list or string

    :param zoom: Defines the zoom level of the map, which determines the
        magnification level of the map.
    :type zoom: int

    :param scale: Affects the number of pixels that are returned.
    :type scale: int

    :param format: Defines the format of the resulting image.
    :type format: string

    :param maptype: defines the type of map to construct. There are several
        possible maptype values, including roadmap, satellite, hybrid,
        and terrain.
    :type maptype: string

    :param language: defines the language to use for display of labels on
        map tiles.
    :type language: string

    :param region: defines the appropriate borders to display, based on
        geo-political sensitivities.
    :type region: string

    :param markers: define one or more markers to attach to the image at
        specified locations.
    :type markers: StaticMapMarker

    :param path: defines a single path of two or more connected points to
        overlay on the image at specified locations.
    :type path: StaticMapPath

    :param visible: specifies one or more locations that should remain visible
        on the map, though no markers or other indicators will be displayed.
    :type visible: list of dict

    :param style: defines a custom style to alter the presentation of
        a specific feature (roads, parks, and other features) of the map.
    :type style: list of dict

    :rtype: iterator containing the raw image data, which typically can be
        used to save an image file locally. For example:

        ```
        f = open(local_filename, 'wb')
        for chunk in client.static_map(size=(400, 400),
                                       center=(52.520103, 13.404871),
                                       zoom=15):
            if chunk:
                f.write(chunk)
        f.close()
        ```
    """

    params = {"size": convert.size(size)}

    if not markers:
        if not (center or zoom is not None):
            raise ValueError("both center and zoom are required"
                             "when markers is not specifed")

    if center:
        params["center"] = convert.latlng(center)

    if zoom is not None:
        params["zoom"] = zoom

    if scale is not None:
        params["scale"] = scale

    if format:
        if format not in MAPS_IMAGE_FORMATS:
            raise ValueError("Invalid image format")
        params['format'] = format

    if maptype:
        if maptype not in MAPS_MAP_TYPES:
            raise ValueError("Invalid maptype")
        params["maptype"] = maptype

    if language:
        params["language"] = language

    if region:
        params["region"] = region

    if markers:
        params["markers"] = markers

    if path:
        params["path"] = path

    if visible:
        params["visible"] = convert.location_list(visible)

    if style:
        params["style"] = convert.components(style)

    response = client._request(
        "/maps/api/staticmap",
        params,
        extract_body=lambda response: response,
        requests_kwargs={"stream": True},
    )
    return response.iter_content()