Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 629
confused Avatar asked Aug 02 '11 17:08

confused


People also ask

Is Google Earth live?

Google Earth will now play live video feeds from select locations across the globe. The feature is available outright on different platforms supported by Google Earth.


1 Answers

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/

like image 52
Theo Avatar answered Oct 12 '22 11:10

Theo