Touches with Maps

Maps can receive touch events as well. You have already seen how touching a map can bring up a zoom control or allow us to pan the map sideways. These are built-in functions of maps. But what if we want to do something different? We’re going to show you how to implement some interesting functionality with maps, including the ability to click a location and get its latitude and longitude. From there, we can do lots of very useful things.

One of the main classes for maps is MapView. This class has an onTouchEvent() method just like the Views we covered earlier and takes a MotionEvent object as its only argument. We can also use the setOnTouchListener() method to set up a callback handler for touch events on a MapView. Other main ...

Get Pro Android 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.