You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I also needed the streetview API, so I make the method for it. Write this at the start of your code:
fromgooglemaps.clientimportmake_api_methodimportgooglemapsdefstreetview(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 """iftype(location) notin (str, dict):
raiseValueError(
"Valid values for the `location` param for ""`streetview` are string or dict (lat/lng Object), ""the given value is invalid: '%s'"%input_type
)
iftype(location) ==dictand ("lat"notinlocationor"lng"notinlocation):
raiseValueError(
"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
)
ifsize:
iftype(size) !=listorlen(size) !=2:
raiseTypeError(
"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
} |kwargsreturnclient._request("/maps/api/streetview", params, extract_body=lambdax: x.content)
googlemaps.Client.streetview=make_api_method(streetview)
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.
Activity
Ledge2494 commentedon Apr 2, 2025
Hello @tjwebb,
I also needed the streetview API, so I make the method for it. Write this at the start of your code:
Example usage:
This output
bytesobject 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: valueto the function call corresponding to the documentation.I provide this code with no guaranty nor support.