Google Street View zoom to Fov
Asked Answered
S

2

5

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

Seritaserjeant answered 10/2, 2016 at 22:27 Comment(0)
S
9

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

Seritaserjeant answered 11/2, 2016 at 18:49 Comment(1)
Is this the right way. I saw var fov = 180 / Math.pow(2,zoom) give me more precise results?Sludge
I
3

You can use the following formula to convert fov to zoom:

  • fov to zoom:

    zoom = Math.log(180/fov)/(Math.log(2))

Or vice versa:

  • zoom to fov:

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

original answer

Indispensable answered 18/12, 2017 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.