【正文】
boundCenterBottom(marker)。}Overrideprotected OverlayItem createItem(int i) {return((i))。(new OverlayItem(getPoint(,), The Downtown Club, Original home of the Heisman Trophy))。 (new OverlayItem(getPoint(,), Lincoln Center, Home of Jazz at Lincoln Center))。=marker。 private Drawable marker=null。().add(new SitesOverlay(marker))。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。}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。Return(true)。return(true)。s current location or a location saved with some data in your activity. To change the map39。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)。s not terribly useful when they have the whole world in their hands.Since a map of the world is not much good by itself, we need to add a few things, as described next.Exercising Your ControlYou can find your MapView widget by findViewById(), just as with any other widget. The widget itself offers a 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 locationbased services (covered in Chapter 32) to show where the device is and where it is going.Fortunately, integrating basic mapping features into your Android project is fairly easy. And there is also a fair bit of power available to you, if you want to get fancy.Terms, Not of EndearmentIntegrating Google Maps into your own application requires agreeing to a fairly lengthy set of legal terms. These terms include clauses that you may find unpalatable.If you are considering Google Maps, please review these terms closely to determine if your intended use will not run afoul of any clauses. You are strongly remended to seek professional legal counsel if there are any potential areas of conflict.Also, keep your eyes peeled for other mapping options, based on other sources of map data, such as OpenStreetMap ().Piling OnAs of Android , Google Maps is not strictly part of the Android SDK. Instead, it is part of the Google APIs addon, an extension of the stock SDK. The Android addon system provides hooks for other subsystems that may be part of some devices but not others.NOTE: Google Maps is not part of the Android open source project, and undoubtedly there will be some devices that lack Google Maps due to licensing issues. For example, at the time of this writing, the Archos 5 Android tablet does not have Google Maps.By and large, the fact that Google Maps is in an addon does not affect your daytoday development. However, bear in mind the following:You will need to create your project with a suitable target to ensure the Google Maps APIs will be available.To test your Google Maps integration, you will also need an AVD that supports the Google Maps API.The Bare BonesFar and away the simplest way to get a map into your application is to create your own subclass of MapActivity. Like ListActivity, which wraps up some of the smarts behind having an activity dominated by a ListView, MapActivity handles some of the nuances of setting up an activity dominated by a MapView.In your layout for the MapActivity subclass, you need to add an element named, at the time of this writing, . This is the longhand way to spell out the names of widget classes, by including the full package name along with the class name. This is necessary because MapView is not in the namespace. You can give the MapView widget whatever Android:id attribute value you want, plus handle all the layout details to have it render properly alongside your other widgets.However, you do need to have these two items:Android:apiKey, which in production will need to be a Google Maps API keyAndroid:clickable=true, if you want users to be able to click and pan through your mapFor example, from the Maps/NooYawk sample application, here is the main layout:?xml version= encoding=utf8?RelativeLayout xmlns:Android=Android:layout_width=fill_parent Android:layout_height=fill_parent Android:id=+id/map Android:layout_width= fill_parentAndroid:layout_height=fill_parent Android:apiKey=YOUR_ API_KEY Android:clickable=true //RelativeLayoutWe39。Reilly Media,2005.[14] (美)李偉夢著,何晨光,李洪剛譯.Android 編程入門經(jīng)典(移動與嵌入式開發(fā)技術(shù))[M]. 北京: 清華大學(xué)出版社,2012.[15] (英)哈諾德著,朱濤江,林劍譯.Java網(wǎng)絡(luò)編程(第3版)——O’Reill