June 18, 2018
Hot Topics:

Mapping with Google APIs in Android, Page 2

  • Updated: February 15, 2012
  • By Chunyen Liu
  • Send Email »
  • More Articles »

Panning, Zooming, and Toggling Map Modes

As was mentioned before, MapController is used to pan and zoom a map. You need to associate each button with a click listener. One example is as follows:

// Set up the button for "Pan East"

mPanE = (Button)findViewById(R.id.pane);

mPanE.setOnClickListener(new OnClickListener(){

// @Override

public void onClick(View arg0) {




The panEast() function is implemented to pan a quarter of the current screen width. Other panning functionalities are done in a similar fashion. Actually, the map itself is already draggable if the device is equipped with a touch screen input. For non-touch-screen devices, you use these buttons or the arrow keys of the rocker pad to pan the map.

public void panEast() {

GeoPoint pt = new GeoPoint(



+ mMapView.getLongitudeSpan() / 4);




Zooming is done simply by increasing or decreasing the current zoom level through the controller.

public void zoomIn() {

mOverlayController.setZoom(mMapView.getZoomLevel() + 1);



To toggle the map display for viewing satellite imagery or traffic, you can enable it directly from MapView.

public void toggleSatellite() {

if (mMapView.isSatellite())







public void toggleTraffic() {

if (mMapView.isTraffic())






Figures 2 and 3 show the results of toggling.

Click here for larger image

Figure 2. Satellite Imagery

Click here for larger image

Figure 3. Traffic on Satellite Imagery


Page 2 of 5

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date