Search code examples
javascriptgoogle-mapsgoogle-maps-api-3google-street-view

Google Street View zoom to Fov


I need to save Street view image exactly as user selected (including panoID, heading, pitch and fov). I have the following code:

            panorama = new google.maps.StreetViewPanorama(document.getElementById('pano'));
            panorama.addListener('pano_changed', function () {
                $('#panoID').val(panorama.getPano());
            });
            panorama.addListener('pov_changed', function () {
                $('#heading').val(panorama.getPov().heading);
                $('#pitch').val(panorama.getPov().pitch);
                $('#fov').val(panorama.getZoom());
            });

problem is I want to save zoom as fov value https://developers.google.com/maps/documentation/streetview/intro (look at fov optional parameter)

fov (default is 90) determines the horizontal field of view of the image. The field of view is expressed in degrees, with a maximum allowed value of 120. When dealing with a fixed-size viewport, as with a Street View image of a set size, field of view in essence represents zoom, with smaller numbers indicating a higher level of zoom.

I found some "convertation" information https://developers.google.com/maps/documentation/javascript/streetview#TilingPanoramas

enter image description here

but it tells, that fov can be till 180, but prev. link tells 120 value is maximum. Why? Of course, I can find ratio for convertation, but maybe exists normal way (i.e. panorama returns Fov instead of zoom)?

Also, seems, catch zoom in pov_changed is not the best way. Sometimes zoom is not updated properly


Solution

  • Found the following function to convert from zoom to FOV:

    var k = Math.pow(0.5051, zoom);
    var fov = 103.7587 * k;
    

    it works (almost exactly) :)

    ADDED

    more precise results:

    var fov = 180 / Math.pow(2,zoom) 
    

    thanks to trungk18