Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving icons on a Android MapView

I'm working on an application that displays the location of moving items on a Google MapView. I need a way to update the position of the icons that represent the items (as well as change the facing of the icons every two seconds as updated data comes in).

I currently have an activity in the app that extends MapActivity. On to this I have overlaid a static Overlay that draws some lines on the map and an ItemizedOverlay that draws a static icon.

There is a draw() method that claims to be used by animated overlays, but overriding it to do my animations still doesn't make anything animate.

Do I need to tell the app to make my overlay animate, or do I need to use a different type of overlay?

like image 625
bsberry Avatar asked Sep 25 '10 22:09

bsberry


2 Answers

There are two things that I have in mind about your problem.

First, did you consider using invalidate() on the MapView to force a redraw? That's probably not the most efficient solution, but it should at least get you something you can work from.

Second, you can refresh the items on your map by calling the activity again. Here is an example.

like image 69
UpCat Avatar answered Sep 20 '22 06:09

UpCat


Using built-in capabilities of MapView and Overlays to draw animation will likely kill your perfromance. My suggestion is:

1) Combine MapView with another View. MapView will give you necessary screen coordinates and another view will serve as a canvas for animation. Both views should occupy the same screen positions (use frame layout);

2) Once you get positions of the map marker you want to animate - remove it from map and start doing animation of marker's movements using second view. Here you can leverage specialized android animation classes (i.e. Animation, AnimationUtil, AnimationSet)

3) Once you've done with animation - add marker to mapview overlay, now in its new position and invalidate overlay

Maybe there can be more optimal approach (i.e. use animation directly on MapView canvas), but the bottom line - you should use specialized animation mechanism to prevent perfromance issues.

like image 43
Vladimir Kroz Avatar answered Sep 18 '22 06:09

Vladimir Kroz