I have an object that streams Locations at a rate of between 1 and 10 per second. I would like to my GoogleMap (Android, v2) to continuously and smoothly pan to keep the object near the center of the map. How can I do that?
The naive approach would be simply call GoogleMap.moveCamera upon receipt of each new Location. But, this results in a choppy display; the map hops to each new location instead of smoothly panning to it.
A better approach is to call GoogleMap.animateCamera -- that smoothly pans the camera to the new location. But, when new Locations arrive faster than the animations can complete, each animateCamera call cancels the previous animation and kicks off a new animation. All animations start off slow, then speed up, then quickly decelerate. This means that continuously kicking off new animations means the camera is always panning very slowly and cannot keep up with the actual Locations.
A fix for this problem is to queue incoming Locations while an animation is in progress, then immediately initiate an animation to the most recent Location as soon as the previous animation is finished. This is better than both previous approaches, but it still stops and starts because each animation starts and finishes at a complete stop.
It seems like the only possible approach to achieve the desired effect is to write my own animator which calls moveCamera at a high framerate and handles acceleration, deceleration, and new Locations while moving. The problem with this approach is that I don't know how to throttle my moveCamera updates because I don't know the update framerate of the GoogleMap and there does not seem to be any setFrameRenderedListener method (or similar).
Any suggestions on how to accomplish this effect?