How to get smooth google maps panTo () when your destination is far

I have two points on a google map and I want to move between them using smooth animation. Using the map.panTo () method, I can pan them, but the animation only works if the second point is less than the width / height of the map.

So, the idea I came up with is to break the transition into something like:

 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....

Thus, the journey is divided into minimal steps. The problem is that I cannot figure out how to implement this in code (recursive midpoint check). Any help would be great.

page with this problem is related to http://amishh4cker.com/geocaching.html

+3
1
if ( end - start ) &gt width and ( end - start ) &lt maxpandistance then
  midpoint = start + ( end - start ) * .5
  while midpoint is not on screen
    midpoint = start + ( midpoint - start ) * .5
  loop

  panto midpoint
else
  panto end

- , , , .

0

Source: https://habr.com/ru/post/1771510/


All Articles