Skip to content

Street View Static API #530

Open
Open

Description

@tjwebb

This library supports the static map API. It should also support the Static Street View API in the same way.

https://developers.google.com/maps/documentation/streetview/overview

Activity

  1. added
    triage meI really want to be triaged.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Jul 24, 2024
  2. Ledge2494 commented on Apr 2, 2025

    @Ledge2494

    Hello @tjwebb,

    I also needed the streetview API, so I make the method for it. Write this at the start of your code:

    from googlemaps.client import make_api_method
    import googlemaps
    
    def streetview(client, location, size=None, **kwargs):
        """Get static image from Streetview API
    
        :param location: The latitude/longitude value representing the location to
            look up or a string
        :type location: string, dict
    
        :param size: The width/height value representing the image size to request
        :type size: list
    
        :param kwargs: Optional parameters available at https://developers.google.com/maps/documentation/streetview/request-streetview
        Warn: these parameter are not verified and you are responsible for the formatting
    
        :rtype: bytes
        """
        if type(location) not in (str, dict):
            raise ValueError(
                "Valid values for the `location` param for "
                "`streetview` are string or dict (lat/lng Object), "
                "the given value is invalid: '%s'" % input_type
            )
        
        if type(location) == dict and ("lat" not in location or "lng" not in location):
            raise ValueError(
                "Invalid value for the 'location' param "
                "the dict passed misses at least one of "
                "the following key 'lat', 'lng' "
                "the given value is invalid: '%s'" % location
            )
        
        if size:
            if type(size) != list or len(size) != 2:
                raise TypeError(
                    "Invalid type for the 'size' param "
                    "size should be of type list containing "
                    "width and height as integers "
                    "the given value is invalid: '%s'" % size
                )
            size = "{}x{}".format(*size)
        else:
            size = "600x400"
    
        params = {
            "location": "{lat},{lng}".format(**location),
            "size": size
        } | kwargs
        
        return client._request("/maps/api/streetview", params, extract_body=lambda x: x.content)
    
    googlemaps.Client.streetview = make_api_method(streetview)

    Example usage:

    gmaps = googlemaps.Client(key="your-key")
    
    test_streetview = gmaps.streetview(location={'lat': 0, 'lng': 0})

    This output bytes object corresponding to the image data in jpeg, you can use Pillow or other lib of your choice to parse the image.
    If you need to use optional parameters, just add key: value to the function call corresponding to the documentation.

    I provide this code with no guaranty nor support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions