【正文】
getMapController() method. Between the MapView and MapController, you have a fair bit of capability to determine what the map shows and how it behaves. The following sections cover zoom and center, the features you will most likely want to use.ZoomThe map of the world you start with is rather broad. Usually, people looking at a map on a phone will be expecting something a bit narrower in scope, such as a few city blocks.You can control the zoom level directly via the setZoom() method on the MapController. This takes an integer representing the level of zoom, where 1 is the world view and 21 is the tightest zoom you can get. Each level is a doubling of the effective resolution: 1 has the equator measuring 256 pixels wide, while 21 has the equator measuring 268,435,456 pixels wide. Since the phone39。s display probably doesn39。t have 268,435,456 pixels in either dimension, the user sees a small map focused on one tiny corner of the globe. A level of 16 will show several city blocks in each dimension, which is probably a reasonable starting point for experimentation.If you wish to allow users to change the zoom level, call setBuiltInZoomControls (true)。, and the user will be able to zoom in and out of the map via zoom controls found at the bottom center of the map.CenterTypically, you will need to control what the map is showing, beyond the zoom level, such as the user39。s current location or a location saved with some data in your activity. To change the map39。s position, call setCenter() on the MapController.The setCenter() method takes a GeoPoint as a parameter. A GeoPoint represents a location, via latitude and longitude. The catch is that the GeoPoint stores latitude and longitude as integers representing the actual latitude and longitude multiplied by 1E6. This saves a bit of memory versus storing a float or double, and it greatly speeds up some internal calculations Android needs to do to convert the GeoPoint into a map position. However, it does mean you must remember to multiply the realworld latitude and longitude by 1E6.Rugged TerrainJust as the Google Maps service you use on your fullsize puter can display satellite imagery, so can Android maps.MapView offers toggleSatellite(), which, as the name suggests, toggles on and off the satellite perspective on the area being viewed. You can have the user trigger these via an options menu or, in the case of NooYawk, via key presses:@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == ) { ( ! ())。return(true)。}else if(keycode== ) {(true)。Return(true)。} return((keyCode, event))。}Layers upon LayersIf you have ever used the fullsize edition of Google Maps, you are probably used to seeing things overlaid atop the map itself, such as pushpins indicating businesses near the location being searched. In map parlance (and, for that matter, in many serious graphic editors), the pushpins are on a layer separate from than the map itself, and what you are seeing is the position of the pushpin layer atop the map layer.Android39。s mapping allows you to create layers as well, so you can mark up the maps as you need to based on user input and your application39。s purpose. For example, NooYawk uses a layer to show where select buildings are located in the island of Manhattan.Overlay ClassesAny overlay you want to add to your map needs to be implemented as a subclass of Overlay. There is an ItemizedOverlay subclass available if you are looking to add pushpins or the like。 ItemizedOverlay simplifies this process.To attach an overlay class to your map, just call getOverlays() on your MapView and add () your Overlay instance to it, as we do here with a custom SitesOverlay:(0, 0, (),())。().add(new SitesOverlay(marker))。We will take a closer look at that marker in the next section.Drawing the ItemizedOverlayAs the name suggests, ItemizedOverlay allows you to supply a list of points of interest to be displayed on the mapspecifically, instances of OverlayItem. The overlay handles much of the drawing logic for you. Here are the minimum steps to make this work:1. Override ItemizedOverlayOverlayItem as your own subclass (in this example, SitesOverlay).2. In the constructor, build your roster of OverlayItem instances, and call populate() when they are ready for use by the overlay.3. Implement size() to return the number of items to be handled by the overlay.4. Override createItem() to return OverlayItem instances given an index.5. When you instantiate your ItemizedOverlay subclass, provide it with a Drawable that represents the default icon (., a pushpin) to display for each item.The marker from the NooYawk constructor is the Drawable used for step 5. It shows a pushpin.You may also wish to override draw() to do a better job of handling the shadow for your markers. While the map will handle casting a shadow for you, it appears you need to provide a bit of assistance for it to know where the bottom of your icon is, so it can draw the shadow appropriately.For example, here is SitesOverlay: private class SitesOverlay extends ItemizedOverlayOverlayItem { private ListOverlayItem items=new ArrayListOverlayItem()。 private Drawable marker=null。public SitesOverlay(Drawable marker){super(marker)。=marker。(new OverlayItem(getPoint(,), UN, United Nations))。 (new OverlayItem(getPoint(,), Lincoln Center, Home of Jazz at Lincoln Center))。 (new OverlayItem (getPoint(,), Carnegie Hall, Where you go with practice, practice, practice))。(new OverlayItem(getPoint(,), The Downtown Club, Original home of the Heisman Trophy))。populate()。}@Overrideprotected OverlayItem createItem(int i) {return((i))。}@Overridepublic void draw(Canvas canvas, MapView mapView, boolean shadow) (canvas, mapView, shadow)。boundCenterBottom(marker