0

I'm trying to make my geolocation app work and after a lot of verification and console.log() functions, everything should work. My problem is that it doesn't actually work. I only have a grey background instead of the StreetView I want.

Here is the code :

StreetView: function (latitude, longitude) {
    $('#streetview').css({'width': $(window).width(), 'height': $(window).height()});

    var lookTo = {lat:  parseFloat(latitude), lng:  parseFloat(longitude)};
    var latlong = new google.maps.LatLng(parseFloat(latitude), parseFloat(longitude));
    var panoOptions = {
        position: lookTo,
        panControl: false,
        addressControl: false,
        linksControl: false,
        zoomControlOptions: false
    };
    // initialize a new panorama API object and point to the element with ID streetview as container
    var pano = new google.maps.StreetViewPanorama(document.getElementById('streetview'), panoOptions);
    // initialize a new streetviewService object
    var service = new google.maps.StreetViewService;
    // call the "getPanoramaByLocation" function of the Streetview Services to return the closest streetview position for the entered coordinates
    console.log('Pano Positon :'+ pano.getPosition());
    service.getPanoramaByLocation(pano.getPosition(), 50, function (panoData) {
        // if the function returned a result
        if (panoData != null) {
            // the GPS coordinates of the streetview camera position
            var panoCenter = panoData.location.latLng;
            console.log('PanoCenter' + panoCenter);
            // the "computeHeading" function calculates the heading with the two GPS coordinates entered as parameters
            var heading = google.maps.geometry.spherical.computeHeading(panoCenter, latlong);
            console.log('Heading : '+ heading);
            // now we know the heading (camera direction, elevation, zoom, etc) set this as parameters to the panorama object
            var pov = pano.getPov();
            pov.heading = heading;
            pano.setPov(pov);
            // set a marker on the location we are looking at, to verify the calculations were correct
            var marker = new google.maps.Marker({
                map: pano,
                position: lookTo
            });
        } else {
            // no streetview found
            console.log('not found');
        }
    });

}

I copied a part of code I find about Google API and there were comments. So it should be readable. If someone has an idea ...

2 Answers2

0

Try to set zoom parameter. If this does not work, please be note that versions 3.20, 3.21, 3.22 are not available anymore as stated in this forum. Check this documentation. If your browser is Internet Explorer, please ensure that you use supported version and do not use a compatibility mode.

Check these related questions:

Use google.maps.StreetViewService.getPanoramaByLocation() to determine if there is a panorama available for the given location.

Hope this helps!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
0

Thank you for your answer.

Actually, I found what was wrong. I didn't have the Whitelist Plugin installed.

So the line : <access origin='*' /> wasn't interpreted. And I was calling this function (the StreetView function) after getting the Google Api script via $.getScript. The Ajax call was never called beacause cross-domain requests weren't accepted.