O'Reilly logo

Android Application Development by G. Blake Meike, Zigurd Mednieks, John Lombardo, Rick Rogers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with MapViews

The MapView encapsulates a lot of very complex mapping software and is available for you in your Android applications—for free. Here are some of the things you can do with a MapView, with only a little programming on your part:

  • Show a street map of any area in the world, with up-to-date mapping information courtesy of Google

  • Change the MapView to show:

    Street view

    Photographs taken at street level for many areas in North America

    Satellite view

    An aerial, photographic view of the area

    Traffic view

    Real-time traffic information superimposed on the map or satellite views

  • Move the map under program control

  • Plot your own graphics in overlays on top of the map

  • Respond to user touch events on the map

MapView and MyLocationOverlay Initialization

The map in MicroJobs has two modes:

  • At startup, and when we select “Current Location” from the Spinner, we want to display a map of our current location, and we want that map to track us as we move around. For this map we will use the MyLocationOverlay class.

  • When we select a specific location from the Spinner, we want to display a map of that location, turn off location updates, and not track movement.

Let’s look again at the code in MicroJobs.java that initializes the MapView and the MyLocationOverlay that tracks our current location:

@Override
 public void onCreate(Bundle savedInstanceState) {

...

     mvMap = (MapView) findViewById(R.id.mapmain);

     // get the map controller
     final MapController mc = mvMap.getController(); mMyLocationOverlay = new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required