Login     Sign Up
Tugadar Networking Community (@admin)
7 months ago

The MapView class is a View that displays the actual map; it includes several options for deciding how the map is displayed.

By default, the Map View will show the standard street map, as shown in Figure 7-5. In addition, you can choose to display a satellite view, StreetView, and expected traffic, as shown in the code snippet below:




You can also query the Map View to find the current and maximum available zoom level, as well as the center point and currently visible longitude and latitude span (in decimal degrees). The latter (shown below) is particularly useful for performing geographically limited Geocoder lookups:

GeoPoint center = mapView.getMapCenter();

int latSpan = mapView.getLatitudeSpan();

int longSpan = mapView.getLongitudeSpan();

You can also optionally display the standard map zoom controls. The following code snippet shows how to get a reference to the Zoom Control View and pin it to a screen location. The Boolean parameter lets you assign focus to the controls once they’re added.

int y = 10;

int x = 10;

MapView.LayoutParams lp;

lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,


x, y,


View zoomControls = mapView.getZoomControls(); mapView.addView(zoomControls, lp); mapView.displayZoomControls(true);

The technique used to pin the zoom controls to the MapView is covered in more detail later in this chapter.