url¶
This module allows the user to input a valid Google Street View URL, set an image size (width and height), and the code downloads the relevant file using a hidden thumbnail API replicating the angle and zoom of the image represented by the URL, which would be roughly seen on the Street View web app.
Here is an example of a valid Street View URL. https://www.google.co.uk/maps/@51.5002793,-0.1490781,3a,87.2y,170.82h,66.46t/data=!3m6!1e1!3m4!1sL3GLvqpla79_pSq2fxUunw!2e0!7i16384!8i8192?entry=ttu
Dissecting this example URL provides the following useful information:
Latitude = 51.5002793 = degrees north or south of the equator.
Longitude = -0.1490781 = degrees east or west of the prime meridian.
Pitch = 87.2 = vertical camera orientation in degrees, where horizontal = 90.
Yaw = 170.82 = bearing in degrees relative to North.
FOV = 66.46 = field of view in degrees (smaller FOV, greater zoom).
Panorama ID = L3GLvqpla79_pSq2fxUunw
Module Contents¶
Classes¶
Relevant parsed street view URL information. |
Functions¶
|
Takes a Google Street View URL and returns an JPEG image in bytes with a |
|
Takes a Google Street View URL and returns a PIL image with a |
|
Thoroughly validates and parses a Google Street View URL. |
Attributes¶
- url.MAX_FOV = 90¶
- url.MAX_LATITUDE = 90¶
- url.MAX_LONGITUDE = 180¶
- url.MAX_PITCH = 179¶
- url.MAX_YAW = 360¶
- url.MIN_FOV = 15¶
- url.MIN_LATITUDE¶
- url.MIN_LONGITUDE¶
- url.MIN_PITCH = 1¶
- url.MIN_YAW = 0¶
- url.PANORAMA_ID_PREFIX = '1s'¶
- class url.StreetViewURL¶
Relevant parsed street view URL information. The toplevel documentation explains each attribute.
Whilst usually returned after URL parsing, the user may initialise an instance themselves, ensuring all inputs are valid.
- fov: float¶
- latitude: float¶
- longitude: float¶
- panorama_id: str¶
- pitch: float¶
- yaw: float¶
- url.get_image(url: str, width: int = DEFAULT_WIDTH, height: int = DEFAULT_HEIGHT) bytes¶
Takes a Google Street View URL and returns an JPEG image in bytes with a given width and height representing the input URL, with the correct yaw, pitch and FOV.
Note: the thumbnail API has slightly limited resolution so the image may be scaled up by the code if needed, without quality improvement.
- url.get_pil_image(url: str, width: int = DEFAULT_WIDTH, height=DEFAULT_HEIGHT) PIL.Image.Image¶
Takes a Google Street View URL and returns a PIL image with a given width and height representing the input URL, with the correct yaw, pitch and FOV.
Note: the thumbnail API has slightly limited resolution so the image may be scaled up by the code if needed, without quality improvement.
- url.parse_url(url: str) StreetViewURL¶
Thoroughly validates and parses a Google Street View URL. Upon success, return a StreetViewURL object providing key information.
This function can be powerfully used to parse a URL for its panorama ID, by accessing the panorama_id attribute of the return object.
Key requirements:
Valid Google domain followed by /maps/
Valid latitude and longitude.
- Valid a, y, h, t values in the URL (h can be omitted, 0 by default).
y is pitch, h is yaw, t is FOV, a is irrelevant but must be present.
Panorama ID is followed by ‘1s’ and must be deducible and valid.
Other extra data is ignored, including query parameters.