Javascript 当目的地很远时,如何获得平滑的Google maps panTo()

Javascript 当目的地很远时,如何获得平滑的Google maps panTo(),javascript,google-maps,recursion,Javascript,Google Maps,Recursion,我在谷歌地图上有两个点,我想用平滑动画在它们之间转换。使用map.panTo()方法,我可以平移到它们,但只有当第二个点小于贴图的宽度/高度时,动画才起作用 因此,我提出的想法是将过渡分解为以下内容: var destination = next point get center check if the destination is in bounds if so panTo it else get the midpoint between center and po

我在谷歌地图上有两个点,我想用平滑动画在它们之间转换。使用map.panTo()方法,我可以平移到它们,但只有当第二个点小于贴图的宽度/高度时,动画才起作用

因此,我提出的想法是将过渡分解为以下内容:

 var destination = next point 
 get center

 check if the destination is in bounds
 if so
   panTo it
 else
   get the midpoint between center and point
   if midpoint in bounds pan 
   else get midpoint etc....
因此,在这里,旅行被分成尽可能小的步骤。 问题是,我不知道如何在代码中实现这一点(即递归中点检查),任何帮助都会很好

我遇到这个问题的页面是

如果(结束-开始)>宽度和(结束-开始)<最大距离,则 中点=起点+(终点-起点)*.5 而中点不在屏幕上 中点=起点+(中点-起点)*.5 环 潘托中点 其他的 潘托端
类似的情况,虽然我可以看到相当长的距离会导致减速,尤其是当窗口变小时。

如果你一直缩小到下一个点在范围内,然后做panTo然后再放大,会怎么样?我已经想到了,但我不想先缩小。正在寻找一种不放大的方法。 if ( end - start ) > width and ( end - start ) < maxpandistance then midpoint = start + ( end - start ) * .5 while midpoint is not on screen midpoint = start + ( midpoint - start ) * .5 loop panto midpoint else panto end