The Street View feature on Google Maps API is now showcasing a cool,

I have been attempting to showcase the interior of various businesses using the Google Maps API street view feature. Initially, I was able to retrieve the place_id and then use it to access any available street view panoramas. However, this functionality suddenly stopped working earlier this week and I'm struggling to pinpoint the cause. The interactive map section now displays as grey with only a few Google artifacts visible, and an error indicating that the generated Google URL returned a 404 status is logged in the console. Has anyone else encountered this issue?

You can also find the code below on my JS Fiddle account.

var map;
var panorama;

$('#thebutton').click(function () {

    map = new google.maps.Map(document.getElementById('map-canvas'));
    var infowindow = new google.maps.InfoWindow();
    var place_id = 'ChIJ-_RcvsBV2YARhkUbjSD3Vi4';
    var placeservice = new google.maps.places.PlacesService(map);
    var placesRequest = {
        placeId: place_id
    };

    placeservice.getDetails(placesRequest, function (results, status) {

        if (status == google.maps.places.PlacesServiceStatus.OK) {
            var marker = new google.maps.Marker({
                map: map,
                position: results.geometry.location
            });
            google.maps.event.addListener(marker, 'click', function () {
                infowindow.setContent(results.name);
                infowindow.open(map, this);
            });
            var brewerystreetview = new google.maps.LatLng(results.geometry.location.A, results.geometry.location.F);

            var sv = new google.maps.StreetViewService();
            panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), {
                center: new google.maps.LatLng(results.geometry.location.lat(), results.geometry.location.lng()),
                zoom: 0
            });
            sv.getPanorama({
                location: brewerystreetview,
                radius: 0
            }, processSVData);
        }
    });
});

function processSVData(data, status) {

    if (status == google.maps.StreetViewStatus.OK) {
        var marker = new google.maps.Marker({
            position: data.location.latLng,
            map: map,
            title: data.location.description
        });

        panorama.setPano(data.location.pano);
        panorama.setPov({
            heading: 0,
            pitch: 0
        });
        panorama.setVisible(true);

        google.maps.event.addListener(marker, 'click', function () {

            var markerPanoID = data.location.pano;
            // Set the Pano to use the passed panoID.
            panorama.setPano(markerPanoID);
            panorama.setPov({
                heading: 0,
                pitch: 0
            });
            panorama.setVisible(true);
            panorama.show();
        });
    }
}

Answer №1

  1. Just a heads up, the .getPanorama function is now available in v3.21 (v.exp), whereas it used to be .getPanoramaById and .getPanoramaByLocation in earlier versions like v3.20 and below. It seems like there was an API change in the experimental version you are currently using.

  2. A word of caution - avoid relying on undocumented properties of the Google Maps Javascript API such as results.geometry.location.A and results.geometry.location.F because they are prone to change with each API update. In most cases where you used these, simply utilize the returned google.maps.LatLng instead of creating a new one.

  3. A StreetViewPanorama object does not have a center option; rather, it should be positioned:

panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), {
    center: results.geometry.location,
    zoom: 0
});     

should be:

panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), {
    position: results.geometry.location,
    zoom: 0
});

updated fiddle link

code snippet:

var map;
var panorama;

$('#thebutton').click(function() {
  map = new google.maps.Map(document.getElementById('map-canvas'));
  var infowindow = new google.maps.InfoWindow();
  var place_id = 'ChIJ-_RcvsBV2YARhkUbjSD3Vi4';
  var placeservice = new google.maps.places.PlacesService(map);
  var placesRequest = {
    placeId: place_id
  };
  placeservice.getDetails(placesRequest, function(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
      var marker = new google.maps.Marker({
        map: map,
        position: results.geometry.location
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(results.name);
        infowindow.open(map, this);
      });
      var brewerystreetview = results.geometry.location;

      var sv = new google.maps.StreetViewService();
      panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'), {
        position: results.geometry.location,
        zoom: 0
      });
      sv.getPanorama({
        location: brewerystreetview,
        radius: 0
      }, processSVData);
    }
  });
});

function processSVData(data, status) {
  if (status == google.maps.StreetViewStatus.OK) {
    var marker = new google.maps.Marker({
      position: data.location.latLng,
      map: map,
      title: data.location.description
    });

    panorama.setPano(data.location.pano);
    panorama.setPov({
      heading: 0,
      pitch: 0
    });
    panorama.setVisible(true);

    google.maps.event.addListener(marker, 'click', function() {

      var markerPanoID = data.location.pano;
      
      panorama.setPano(markerPanoID);
      panorama.setPov({
        heading: 0,
        pitch: 0
      });
      panorama.setVisible(true);
      panorama.show();
    });
  }
}
 div#pano {
   width: 100%;
   height: 400px;
   float: left;
 }
 div#map-canvas {
   width: 100%;
   height: 25%;
   float: left;
 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<div class="container" id="infocontainer" style=""><a href="#" class="btn btn-primary" id="thebutton" onclick="return false;">Click here</a>
</div>
<div id="pano"></div>
<div id="map-canvas"></div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prevent those pesky popups with this handy script

Even though AdBlock sometimes doesn't block popups, I have a solution in mind. I plan to use Greasemonkey and jQuery to create my own popup blocker. Is it possible to intercept the clicks and determine if a popup is about to open? $('.popupLaun ...

The usage of the bootstrapTable() function creates a gap below the displayed table information

Currently, I am working on incorporating a table into my webpage that will load data from an API. After some research, I found a Bootstrap table library to assist with this task. However, I have encountered an issue with setting the table height dynamicall ...

What is the best way to change the active tab in a slider using JQuery?

I've been working on a tabbed slider that should change the color of the active tab, however, I'm having trouble getting it to switch properly. The tabs themselves are functioning correctly, but for some reason, the active class isn't changi ...

Retrieving data from an external API using Express.js and displaying it on a website

I'm facing a challenge in handling a solution with node.js and express.js utilizing pug for rendering HTML. I need to render on a single page by retrieving values from separate HTTP GET requests from different websites. My goal is for express/node to ...

Error in TypeScript while running the command "tsd install jquery" - the identifier "document" could not be found

Currently, I am facing an issue with importing jQuery into my TypeScript project. In order to achieve this, I executed the command tsd install jquery --save, which generated a jquery.d.ts file and added /// <reference path="jquery/jquery.d.ts" /> to ...

Encountered a problem with sending values using jQuery and JSON: Unexpected token 'b'

Can you explain why in this specific scenario there is an error showing up as SyntaxError: Unexpected token b listados:229? response = '{"name":"John"}'; var obj = jQuery.parseJSON(response); $.ajax({ url:urlform, dataType: ...

In my chat application, I encountered the error message "Received an expression instead of an assignment or function call - no-unused-expressions"

While working on my React Chat app and trying to access my Firebase, I encountered the error message: "Expected an assignment or function call and instead saw an expression no-unused-expressions" The error seems to be related to the assignment of this.rem ...

I am unable to employ the useMutation or useQuery features in Apollo Client 3.0

import { useMutation } from '@apollo/client';; function LockedBlog() { const [lockedBlog] = useMutation(LOCKED_BLOG); }; class EditBlog extends Component { state = { ...initialState }; index.js import React from "react"; im ...

Utilizing helper functions in Node based on their specific types

In my helper module, I have different files like content, user, etc. These files define various helpers that can be used in the router. Below is the code for the router: router.js var helper = require("./helper"); function index(response) { response ...

Eliminating padding or margin for figures in Bootstrap on smaller screens

I've been struggling to create a fullscreen image on small devices without any margin or padding. Unfortunately, the solutions suggested in this thread didn't work for me. Below is the code I'm currently using (tested on https://jsfiddle.n ...

How to Use Vanilla JavaScript to Fetch a JSON File, Convert the Data into an Array, and Iterate Through Each Object

Imagine having a JSON file called map.json: { "images":{ "background": ["images/mountains.png","images/sea.png"] } } The goal is for JavaScript to retrieve "images/mountains.png" from map.json and us ...

What is the best way to apply a CSS class to a div element without affecting its child elements using JavaScript?

Currently, I am using JavaScript to add and remove a CSS class through a click event. Within my div structure, I have multiple similar divs. While I can successfully add and remove the class from my main div, I am facing an issue where the class is also ap ...

Only show a single li element in CSS at a time

I'm working with Angular 2 and I have a list: <ul> <li *ngFor="let show of (ann)"> {{show}} </li> </ul> I want to show one item from the list every 3 seconds in an infinite loop. Here&apos ...

How can I make my image shine when the mouse hovers over

I have recently come across a fascinating effect where an image glows up when the mouse hovers over it. This is not your typical border glow, but rather a unique enhancement of colors within the image itself. I discovered a library called Pixastic that can ...

Implement Offcanvas feature with Bootstrap 3 Navbar set to Fixed Top position

I am in the process of creating a website that will feature a large menu. However, I am not a fan of the collapsed menu that comes with BS3. Instead, I would like to implement a drawer or off-canvas menu similar to the one showcased in BS3's offcanvas ...

Ways to retrieve textStatus beyond ajax boundaries

Do you know how to access the textStatus variable after an ajax call? I need to use this variable in an if condition. Can anyone provide assistance? $this->registerJs("colorArray = ['#ff4c4c','#32CD32']; $('.grooveTable&apo ...

Tips for getting the setInterval function to work with a progress bar even when a tab is not in focus

After browsing through similar questions, I couldn't find the answer I was looking for. As a newbie in programming experimenting with JavaScript Progress Bar, I encountered an issue where the progress bar would pause and the counter wouldn't coun ...

What is a common mistake when using refs in React?

I've recently started diving into React. I've seen conflicting opinions on using refs - some sources claim it's a bad practice altogether. Can someone clarify this for me? Is it harmful to attach refs to child components in order to access ...

React and SASS - issue with checkbox component not being properly aligned with its label

I'm brand new to React and I'm currently in the process of converting a pure HTML page into a React component. How can I adjust the SASS stylesheet to match the original HTML layout? Here is my current React setup (the checkbox displays on the r ...

Utilizing external JSON data in JavaScript for retrieval

Is there a way to retrieve the value of categories.name_category in JavaScript? The AJAX call to the REST API is functioning correctly: I attempted to access it like this, but unfortunately it did not work as expected: Currently utilizing the Moustache f ...