开发者

How to detect Google MapView movement in Android?

I'd like to dynamically update the map/ load new map overlays every time my user moves it a certain amount of d开发者_StackOverflowistance. How do I go about doing this? Is there a listener for every time the user moves the map? Most likely I'd just measure the distance between the center points.

Thanks!


Try this to detect the map movements: http://pa.rezendi.com/2010/03/responding-to-zooms-and-pans-in.html

On start and after the map has been moved, you should save the current map center. As the article suggests, track ACTION_UP to determine when the user has finished a map movement. Then, compare the new map center with the old map center. To get the map centers use MapView's getMapCenter():

http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/MapView.html#getMapCenter()

EDIT: I have done some additional work on this, and have a complete application with code for your enjoyment. This blog post explains a timer solution to this and contains a link to Github source: http://bricolsoftconsulting.com/extending-mapview-to-add-a-change-event/


The map interface unfortunately does not include any listeners to monitor map actions (zoom/pan). You'll need to set up a timer of some sort that checks the center/zoom levesl to figure out if things have changed and update accordingly.


You could do this by overriding the onTouch(...) method in your Activity (so that every time the user pans the map, you could recalculate the map boundaries). You would need to know the map's zoom level and boundaries, etc, in order to load these overlays based on map distances.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜