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 View
s 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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.