Add a street view image to your app with the Google Street View Static API

Need street view in an email, PDF or app? The Google Street View Static API returns a plain image from a URL, no JavaScript needed.

Add a street view image to your app with the Google Street View Static API

In this blog post, I’ll show you how to add a static Street View image to your website or app with a single HTTP request to the Google Street View Static API. Because it returns a plain image and needs no Javascript, it’s ideal for emails, PDFs and anywhere else that can’t run code. As usual, I’ll cover common use cases, walk through a worked example with full source code, and share a live demo you can try at https://google-static-streetview.afi.dev/.

Part 1: The complete Google Street View API guide
Part 2: Add a street view image to your app with the Google Street View Static API (this article)
Part 3: Add interactive panoramas to your app using Dynamic Street View
Part 4: Use Google Street View for free by calling the Google Maps embed API
Part 5: Google Street View Insights: Analyze Google Street View images at scale

Embed a static (non-interactive) Street View panorama or thumbnail into your web page
Embed Google Street View images with a simple URL

What is the Google Street View Static API?

The Google Street View Static API is a web service that returns a Street View image for a given location. Street View imagery is made up of panoramas, 360 degree photos taken at points along a road or path. The API finds the panorama nearest to the your location and returns a flat image cropped from it. You can specify the location as a latitude/longitude pair, an address, or a Google Place ID.

Google Street View Static API example

Here's how you get the street view image for 1800 Cornwall Avenue in the beautiful neighborhood of Kitsilano, Vancouver.

Endpoint: GET

https://maps.googleapis.com/maps/api/streetview?
size={SIZE}&
location={LOCATION}&
key={YOUR_API_KEY}

{SIZE} specifies the output size of the image in pixels. Size is specified as {width}x{height} e.g. size=600x400 returns an image 600 pixels wide, and 400 high.

{LOCATION} can be a text string (such as 1800 Cornwall Avenue, Vancouver), a latitude and longitude coordinates pair (49.2724355, -123.1455706), or a Place ID prefixed with place_id: (such as place_id:EiwxODAwIENv), and should be URL-encoded. 

{YOUR_API_KEY} is your Google Maps API key with the Google Street View API enabled.

There are also three optional parameters that are super useful:

{HEADING} indicates the compass heading of the camera. Accepted values are from 0 to 360 (both values indicating North, with 90 indicating East, and 180 South). If you don't specify a heading, a value is calculated that directs the camera towards the specified location, from the point at which the closest photograph was taken. The Street View API finds the nearest panorama and automatically points the camera toward that address, so leaving heading out often gives a better result than setting it yourself.

{FOV} (default 90) sets the image’s horizontal field of view in degrees, up to a maximum of 120. Because a Street View image has a fixed size, the field of view effectively controls zoom: the smaller the number, the more zoomed in the image appears.

{PITCH} (default is 0) specifies the up or down angle of the camera relative to the street view vehicle. This is often, but not always, flat horizontal. Positive values angle the camera up (with 90 degrees indicating straight up) while negative values angle the camera down (with -90 indicating straight down).

Endpoint: GET

https://maps.googleapis.com/maps/api/streetview?size=600x300&location=1800%20Cornwall%20Avenue%2C%20Vancouver%2C%20BC%2C%20Canada&key={YOUR_API_KEY}

Response

The response is the street view image itself (not JSON, which is how most Google Maps APIs return data). A successful request returns a JPEG (content type image/jpeg) at the dimensions you set with size, so you can drop the request URL straight into an <img> tag src attribute and have the browser render the photo directly, just like this:

<img
  src="https://maps.googleapis.com/maps/api/streetview?size=600x300&location=1800%20Cornwall%20Avenue%2C%20Vancouver%2C%20BC%2C%20Canada&key={YOUR_API_KEY}"
  alt="Street View of 1800 Cornwall Avenue, Vancouver, BC"
  width="600"
  height="300"
/>

Retrieving panorama details with the metadata endpoint

As you can see, the Google Street View Static API only returns an image. If you want to find out when the street view image was taken, its exact GPS coordinates or its Panorama ID (pano_id) so that you can retrieve the same street view image at a later date, you need to call the Metadata endpoint.

Endpoint: GET

https://maps.googleapis.com/maps/api/streetview/metadata?
location={LOCATION}&
key={GOOGLE_MAPS_API_KEY}

Just like with the Street View Static API, {LOCATION} can be a text string (such as 1800 Cornwall Avenue, Vancouver), a latitude and longitude coordinates pair (49.2724355, -123.1455706), or a Place ID prefixed with place_id: (such as place_id:EiwxODAwIENv), and should be URL-encoded. 

{YOUR_API_KEY} is your Google Maps API key with the Google Street View API enabled.

This is the street view metadata for the 1800 Cornwall Avenue example we used earlier.

Endpoint: GET

https://maps.googleapis.com/maps/api/streetview/metadata?location=1800%20Cornwall%20Avenue%2C%20Vancouver%2C%20BC%2C%20Canada&key={GOOGLE_MAPS_API_KEY}

Response

{
    "copyright": "© 2026 Google",
    "date": "2024-08",
    "location": {
        "lat": 49.27243602995181,
        "lng": -123.1455566626002
    },
    "pano_id": "FRV4hPQCV-Si_IZcxNRJYQ",
    "status": "OK"
}

The metadata endpoint is free to call, so you can use it to check whether a street view panorama exists near your location before requesting an image. If there isn't one, the response is { "status": "ZERO_RESULTS" }.

Google Street View Static API use cases

The Street View Static API costs $7 per 1,000 requests, half what you'd pay for an interactive panorama. The Static API is more than enough if your users just need a quick look at a place. A common use case is adding street view images to the stop list in a driver app for a routing or last mile delivery application. Delivery drivers, salespeople, service technicians or anyone using the app can then see exactly where to go and what the entrance looks like before they arrive, which saves time and reduces mistakes.

In fact, the new Search for Destinations endpoint in the Geocoding API returns a streetViewThumbnail object with the Panorama ID for this exact purpose.

Building a Google Street View explorer

In this final section, we'll use the Google Street View Static API to build an app that shows the Street View image for any address or place name you type in. As with most of my tutorials, full source code for for google_static_streetview is available on GitHub. You can also play around with a live demo at https://google-static-streetview.afi.dev/.

How our code is organized

google_static_streetview is a single page React app that uses Vite as the build tool and development server. When the user picks an address from the search box, the app looks up its latitude and longitude with the Places API, checks the free metadata endpoint to see if there's Street View imagery nearby, and if there is, requests the image from the closest panorama.

To get the app up and running quickly, I used @vis.gl/react-google-maps, a React library for the Maps JavaScript API. <APIProvider/> in main.jsx loads the API, and <Map/> and <AdvancedMarker/> in App.jsx draw the map and the marker. That takes care of the map setup in a few lines, so the rest of the code can focus on the Street View Static API.

App.jsx

App.jsx is the app's root component, rendered by main.jsx. Besides drawing the map (<Map/>), the marker (<AdvancedMarker/>) and the search box (<PlaceSearch/>), it keeps track of two pieces of state: place, the location the user picked, and isStreetViewOpen, which controls whether the Street View card is showing.

PlaceSearch.jsx

components/PlaceSearch.jsx holds a search box that uses Google Places Autocomplete to suggest places dynamically as the user types. The search box uses PlaceAutocompleteElement, the newer version of Place Autocomplete built on Places API (New).

Rather than attaching autocomplete to an <input> you create yourself, it's a ready made web component, <gmp-place-autocomplete>, that includes its own input box and suggestion dropdown. You add it to the page, listen for the gmp-select event, and fetch whichever place fields you need. The text input, search icon, clear button and suggestion dropdown all come ready-made with the <gmp-place-autocomplete> web component. That's one of its main benefits over building and styling your own search box. Here's how it works in detail:

When PlaceSearch first renders, the Places library usually hasn't loaded yet, so the effect exits early. Once useMapsLibrary('places') returns the library, the effect runs again and creates a PlaceAutocompleteElement inside the empty <div ref={containerRef} className="PlaceSearch"/>.

/*** components/PlaceSearch.jsx ***/
import { useEffect, useRef } from "react";
import { useMap, useMapsLibrary } from "@vis.gl/react-google-maps";
import "./PlaceSearch.css";

export default function PlaceSearch({ onSelectPlace }) {
  const places = useMapsLibrary("places");
  const map = useMap();
  const containerRef = useRef(null);

  useEffect(() => {
    const container = containerRef.current;
    if (!places || !map || !container) return;

    const autocomplete = new places.PlaceAutocompleteElement();
    container.appendChild(autocomplete);
    //... rest of useEffect
  });
  //... rest of PlaceSearch

  return <div ref={containerRef} className="PlaceSearch" />;
}

The effect adds a listener for the gmp-select event, which fires when the user picks a suggestion from the dropdown. The event's placePrediction is converted to a Place object with placePrediction.toPlace(), and place.fetchFields() then requests its address and coordinates.

/*** components/PlaceSearch.jsx ***/
const handleSelect = async (event) => {
  const { placePrediction } = event;
  const place = placePrediction.toPlace();

  try {
    await place.fetchFields({ fields: ["formattedAddress", "location"] });
  } catch (error) {
    console.error("Could not fetch place details", error);
    return;
  }
  if (!place.location) return;

  //... onSelect code
};
autocomplete.addEventListener("gmp-select", handleSelect);

The place's id, address and location are passed to the onSelectPlace callback. In App.jsx, that's handleSelectPlace, which saves the place in state and opens StreetViewCard.jsx.

onSelectPlace({
  id: place.id,
  address: place.formattedAddress ?? placePrediction.text.toString(),
  location: place.location.toJSON(),
});

StreetViewCard.jsx

The <StreetViewCard/> component (components/StreetViewCard.jsx) displays a popup info window showing the street view image for the selected address. It's a wrapper for the ever so useful <InfoWindow/> component from @vis.gl/react-google-maps. <InfoWindow/> also makes opening and closing simple: it opens when you render it, closes when you stop, and comes with a close button that fires onCloseClick. Passing the marker as the anchor keeps the window attached to it, even as the user pans and zooms the map.

/*** components/StreetViewCard.jsx ***/
return (
  <InfoWindow
    anchor={anchor}
    headerContent={<p className="StreetViewCard-title">{place.address}</p>}
    ariaLabel={`Street View of ${place.address}`}
    maxWidth={IMAGE_SIZE.width + 32}
    shouldFocus={false}
    onCloseClick={() => {
      trackEvent("card_close", { method: "button" });
      onClose();
    }}
  >
    <div className="StreetViewCard-frame">
      {status === "ok" ? (
        <img
          src={imageUrl}
          alt={`Street View of ${place.address}`}
          width={IMAGE_SIZE.width}
          height={IMAGE_SIZE.height}
          onError={markImageError}
        />
      ) : (
        <p className="StreetViewCard-message">{MESSAGES[status]}</p>
      )}
    </div>
  </InfoWindow>
);

Furthermore, any JSX you place inside <InfoWindow/> is rendered into the content area of the info window. With the plain Maps Javascript API, you'd have to pass the content as an HTML string or a DOM node through setContent(), and update it by hand whenever something changed. With React the Street View card's content switches from "Loading Street View…" to the image as soon as the metadata check finishes, no additional code needed.

StreetViewCard.jsx displays the image with an ordinary <img> tag with a src pointing to the Street View Static API URL. The browser loads the picture straight from Google, with no extra code needed.

useStreetViewStatus.js

hooks/useStreetViewStatus.js is a hook (a reusable function that bundles React logic) that calls the Street View Static API's metadata endpoint (through fetchStreetViewMetadata() in streetView.js) to check whether Street View imagery exists near the selected location so you don't waste an API call on an image that doesn't exist. It returns one of four statuses:

  1. checking while it waits for a response,
  2. ok if imagery exists,
  3. unavailable if there's none, and
  4. error if the request fails.
/*** services/useStreetViewStatus.js ***/
useEffect(() => {
  let isCancelled = false;
  const resultKey = `${lat},${lng}`;

  fetchStreetViewMetadata({ lat, lng })
    .then((metadata) => {
      if (isCancelled) return;
      if (metadata.status === "OK") {
        setResult({ key: resultKey, status: "ok" });
      } else if (metadata.status === "ZERO_RESULTS") {
        setResult({ key: resultKey, status: "unavailable" });
      } else {
        setResult({ key: resultKey, status: "error" });
      }
    })
    .catch(() => {
      if (isCancelled) return;
      setResult({ key: resultKey, status: "error" });
    });

  return () => {
    isCancelled = true;
  };
}, [lat, lng]);

StreetViewCard then uses the status to decide what to show: the Street View image when it's ok, or a short message for the other three.

streetView.js

services/streetView.js contains two helper functions for the Street View Static API. streetViewImageUrl() builds the image URL that <StreetViewCard/> uses as its <img> source, and fetchStreetViewMetadata() calls the free metadata endpoint, which useStreetViewStatus uses to check for imagery.

/*** services/streetView.jsx ***/
const STREET_VIEW_API = 'https://maps.googleapis.com/maps/api/streetview'
const API_KEY = import.meta.env.VITE_GOOGLE_MAPS_API_KEY

export const IMAGE_WIDTH = 640
export const IMAGE_HEIGHT = 300

export function streetViewImageUrl(location, { width = IMAGE_WIDTH, height = IMAGE_HEIGHT } = {}) {
  const params = new URLSearchParams({
    size: `${width}x${height}`,
    location: `${location.lat},${location.lng}`,
    source: 'outdoor',
    return_error_code: 'true',
    key: API_KEY,
  })

  return `${STREET_VIEW_API}?${params}`
}

export async function fetchStreetViewMetadata(location) {
  const params = new URLSearchParams({
    location: `${location.lat},${location.lng}`,
    source: 'outdoor',
    key: API_KEY,
  })

  const response = await fetch(`${STREET_VIEW_API}/metadata?${params}`)
  if (!response.ok) {
    throw new Error(`Street View metadata request failed with HTTP ${response.status}`)
  }
  return response.json()
}

Because the Street View Static API returns an image rather than JSON, we don't need to worry about CORS (Cross Origin Resource Sharing) errors, backend proxies or writing asynchronous code (no need for fetch() or await).

Deploy and run

To test the app, simply visit https://google-static-streetview.afi.dev/ and enter an address into the search box on the top right. If you'd like to run the app locally, fork google_static_streetview on GitHub and run npm install to install dependencies. Start the app by running npm run dev then open http://localhost:5173/ in your browser to view it. Remember to update the .env files in both repos with a Google Maps API key that has both the Places API and Street View Static API enabled.

This article was written by Afi Labs, a Google Maps Premier Partner and reseller. We build route optimization, navigation, and fleet tracking software on Google Maps, and offer volume pricing on GMP licensing. Talk to an engineer or follow Afian on LinkedIn.

Next: Add interactive panoramas to your app using Dynamic Street View