Recipe 7.3 Changing Map Modes

Android Versions
Level 1 and above
Permissions
android.permission.INTERNET
Source Code to Download from Wrox.com
Maps-Views.zip

You want to change the different view modes offered by the MapView. This recipe will show you how to display the MapView in satellite mode as well as show the traffic conditions.

Solution

By default, the MapView displays the Google Map in Map mode, which is simply a graphical rendering of the map (see Figure 7-7).

The MapView supports the satellite view, which is a combination of map view and satellite view (see Figure 7-8). To do so, use the setSatellite() method of the MapView class:

package net.learn2develop.maps;

import android.os.Bundle;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;

public class MainActivity extends MapActivity {
    MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

        mapView.setSatellite(true);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

}

If you want to display traffic conditions on the map, use the setTraffic() ...

Get Android Application Development Cookbook: 93 Recipes for Building Winning Apps 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.