February 10, 2012
Hot Topics:
RSS RSS feed

Mapping with Google APIs in Android

  • June 18, 2008
  • By Chunyen Liu
  • Send Email »
  • More Articles »

Figure 1: Initial map centered on a specified position

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) {
      panEast();
   }
});

The panEast() function is implemented to pan a quarter of the current screen size. 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 LCD. For non-touch-screen devices, you use these buttons or the arrow keys of the rocker pad to pan the map.

public void panEast() {
   Point pt = new Point(
      mMapView.getMapCenter().getLatitudeE6(),
      mMapView.getMapCenter().getLongitudeE6()
         + mMapView.getLongitudeSpan() / 4);
   mMapView.getController().centerMapTo(pt, true);
   }

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

public void zoomIn() {
   mMapView.getController().zoomTo(mMapView.getZoomLevel() + 1);
   }

To toggle the map display for viewing satellite imagery or traffic, you can enable it directly from MapView. The results are shown in Figures 2 and 3.

public void toggleSatellite() {
    mMapView.toggleSatellite();
}

public void toggleTraffic() {
    mMapView.toggleTraffic();
}

Figure 2: Satellite imagery





Comment and Contribute

 


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

 

 


Networking Solutions
Sitemap | Contact Us