Google Street View zoom to Fov

2019-05-08 01:34发布

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

2条回答
孤傲高冷的网名
2楼-- · 2019-05-08 02:23

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

查看更多
萌系小妹纸
3楼-- · 2019-05-08 02:32

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

查看更多
登录 后发表回答