当目的地很远时,如何获得平滑的谷歌地图panTo()

时间:2010-10-26 14:13:54

标签: 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 point
   if midpoint in bounds pan 
   else get midpoint etc....

所以在这里旅行被分解成尽可能少的步骤。 问题是,我无法理解如何在代码中实现这一点(递归中点检查)任何帮助都会很棒。

遇到此问题的网页是http://amishh4cker.com/geocaching.html

1 个答案:

答案 0 :(得分:0)

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

类似的东西,虽然我可以看到相当大的距离导致减速,特别是当窗口变小时。