1

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?

Ben
  • 1,272
  • 13
  • 28
  • Side question, if you get so many locations that to go to each one requires your own animator (or continuous panning) how does that work for a user experience perspective as if you are moving the field faster than the user can ingest the info (or get motion sick)? – Morrison Chang Nov 20 '15 at 22:44
  • Continuous panning doesn't imply fast panning. Google Maps' navigation is an example of an app that pans smoothly and continuously. – Ben Nov 20 '15 at 22:51

1 Answers1

1

If I understand you correctly, you envision to make incomming location updates animate the map to keep the device location (or something else) at the center of the map.

It seems that the navigation from Google that you refer to performs some dead reconing, meaning that even with, say, 10 seconds between location updates, the position does not jump from one point to another, but is smoothly moving in a certain heading at a certain speed.

Both heading (bearing) and speed is available in the location updates (if provided by GPS that is).

Sounds to me that something similar may be a way to solve you problem. You would of course still have to determine how much you trust each location update as a outlier would make it 'fast-foward' in a, possibly incorrect, direction. It may be enough to take the accuracy into account and discard those that contains too much uncertainty.

Ultimately you should be able to perform continous camera animations that takes one or more previous updates into account, enabling you to trigger animateCamera each x seconds instead of waiting for location updates.

Hope you get the idea and that it, despite being a bit vague, is helpful to you.

cYrixmorten
  • 7,110
  • 3
  • 25
  • 33
  • I think my question is actually simpler. Let's say I want the map to pan smoothly along a known circular path; how do I do that? Repeated animateCamera calls will result in stops and starts as described in the question. – Ben Nov 21 '15 at 03:36