android毕业设计外文资料翻译--使用mapview和mapactivity显示地图(编辑修改稿)内容摘要:

dings are located in the island of Manhattan. Overlay Classes Any 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, (),())。 6 ().add(new SitesOverlay(marker))。 We will take a closer look at that marker in the next section. Drawing the ItemizedOverlay As 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))。 7 (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()。 } @Override protected OverlayItem createItem(int i) { return((i))。 } @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) (canvas, mapView, shadow)。 boundCenterBottom(marker)。 } @Override protected boolean onTap(int i) { (,(i).getSnippet(), ) .show()。 return(true)。 } @Override public int size() { return(())。 } } Handling Screen Taps An Overlay subclass can also implement onTap(), to be notified when the user taps the map, so the overlay can adjust what it draws. For example, in fullsize Google Maps, clicking a pushpin pops up a bubble with information about the business at that pin39。 s location. With onTap(), you can do much the same in Android. The onTap() method for ItemizedOverlay receives the index of the OverlayItem that was clicked. It is up to you to do something worthwhile with this event. In the case of SitesOverlay, as shown in the preceding section, onTap() looks like this: @Override protected boolean onTap(int i) { (,(i).getSnippet(), ).show()。 8 return(true),} Here, we just toss up a short Toast with the snippet from the OverlayItem, returning true to indicate we handled the tap. My, Myself, and MyLocationOverlay Android has a builtin overlay to handle two mon scenarios:  Showing where you are on the map, based on GPS or other locationproviding logic  Showing where you are pointed, based on the builtin pass sensor, where available All you need to do is create a MyLocationOverlay instance, add it to your MapView39。 s list of overlays, and enable and disable the desired features at appropriate times. The at appropriate times notion is for maximizing battery life. There is no sense in updating locations or directions when the activity is paused, so it is remended that you enable these features in onResume() and disable them in onPause(). For example, NooYawk will display a pass rose using MyLocationOverlay. To do this, we first need to create the overlay and add it to the list of overlays: me=new MyLo。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。