Search code examples
imagegoogle-mapsgoogle-street-view

What to do with the response of Street View Image API?


I just started using the Street View Image API, but when I call it, all it returns is just a huge unreadable string.

How am I supposed to turn that string into an actual image? Thanks.

Here's my AJAX request I made using jQyuery:

        $.ajax({
        method: "GET",
        url: "https://maps.googleapis.com/maps/api/streetview",
        success: function(data) {
            console.log(data);
        },
        data: {
            size: "600x300",
            location: "46.414382,10.013988",
            heading: "151.78",
            pitch: "-0.76",
            key: key
        }
    });

Solution

  • As said by @scaisEdge it returns an image, use the URL directly as src of an <img>:

    jQuery(
      function($) {
        $('#streetview')
          .attr('src', 'https://maps.googleapis.com/maps/api/streetview?' + $.param({
            size: "600x300",
            location: "46.414382,10.013988",
            heading: "151.78",
            pitch: "-0.76",
            //key:key
          })).show();
      }
    );
    #streetview {
      display: none;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <img id="streetview" />