android毕业设计外文资料翻译

3995
    


来源:
Licence:
联系:
分类:
平台:
环境:
大小:
更新:
标签:
联系方式 :
免费下载 ×

下载APP,支持永久资源免费下载

限免产品服务请联系qq:1585269081

下载APP
免费下载 ×

下载APP,支持永久资源免费下载

下载APP 免费下载
下载 ×

下载APP,资源永久免费


如果出现不能下载的情况,请联系站长,联系方式在下方。

免费下载 ×

下载论文助手APP,资源永久免费

免费获取

如果你已经登录仍然出现不能下载的情况,请【点击刷新】本页面或者联系站长


 

 

毕业设计(论文)外文资料翻译

外文出处  Mark Murphy.Beginning       

          Android 2  Chapter 33        

 

Mapping with MapView and MapActivity

One of Google's most popular services-after search of course-is Google Maps, which lets you find everything from the nearest pizza parlor to directions from New York City to San Francisco (only 2,905 miles!), along with supplying street views and satellite imagery.

Most Android devices, not surprisingly, integrate Google Maps. For those that do, there is a mapping activity available to users directly from the main Android launcher. More relevant to you, as a developer, are MapView and MapActivity, which allow you to integrate maps into your own applications. Not only can you display maps, control the zoom level, and allow people to pan around, but you can tie in Android's location-based 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 Endearment

Integrating 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 recommended 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 (http://www.openstreetmap.org/).

Piling On

As of Android l.5, Google Maps is not strictly part of the Android SDK. Instead, it is part of the Google APIs add-on, an extension of the stock SDK. The Android add-on 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 add-on does not affect your day-to-day 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 Bones

Far 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, com.google.android.maps.MapView. 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 com.google.android.widget 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 key
  • android:clickable="true", if you want users to be able to click and pan through your map

For example, from the Maps/NooYawk sample application, here is the main layout:

<?xml version="l.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

   android:layout_height="fill_parent">

  <com.google.android.maps.MapView android:id="@+id/map"

   android:layout_width=" fill_parent"

android:layout_height="fill_parent"

   android:apiKey="<YOUR_ API_KEY>"

   android:clickable="true" />

</RelativeLayout>

We'll cover that mysterious apiKey later in this chapter, in the "The Key to It All" section. In addition, you will need a couple of extra things in your AndroidManifest.xml file:

  • The INTERNET and ACCESS_COARSE_LOCATION permissions (the latter for use with the MyLocationOverlay class, described later in this chapter)
  • Inside your <application>, a <uses-library> element with

android:name ="com.google.android.maps", to indicate you are using one of the optional Android APIs

Here is the AndroidManifest.xml file for NooYawk:

<?xml version=”1.0” encoding=”utf-8”?>

<manifest xmlns:android=”http://schemas.android.com/apk/res/android”

package="com.commonsware.android.maps”>

<uses-permission android:name=”android. permission.INTERNET” />

<uses-permission android:name=”android.permission.ACCESS_COARES_LOCATION” />

<application android:label="@string/app_name"

android:icon="@drawable/cw">

<uses-library  android:name=”com.google.android.maps"/>

<activity android:name=".NooYawk”  android:label="@string/app_name">

<intent-filter>

          <action android:name="android.intent.action.MAIN" />

          <category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

That is pretty much all you need for starters, plus to subclass your activity from MapActivity. If you were to do nothing else, and built that project and tossed it in the emulator, you would get a nice map of the world. Note, however, that MapActivity is abstract. You need to implement isRouteDisplayed() to indicate if you are supplying some sort of driving directions.

In theory, users could pan around the map using the D-pad. However, that'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 Control

You 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.

Zoom

The 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 phone's display probably doesn'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.

Center

Typically, you will need to control what the map is showing, beyond the zoom level, such as the user's current location or a location saved with some data in your activity. To change the map'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 real-world latitude and longitude by 1E6.

Rugged Terrain

Just as the Google Maps service you use on your full-size computer 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:

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

   if (keyCode == KeyEvent.KEYCODE_S) {

                map.setSatellite( ! map.isSatellite());

return(true);

}else if(keycode== KeyEvent.KEYCODE_Z) {

Map.dispalyZoomControls(true);

Return(true);

}

     return(super.onKeyDown(keyCode, event));}

Layers upon Layers

If you have ever used the full-size 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 composition of the pushpin layer atop the map layer.

Android'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 application's purpose. For example, NooYawk uses a layer to show where select buildings 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:

marker.setBounds(0, 0, marker.getIntrinsicWidth(),marker.getIntrinsicHeight());

map.getOverlays().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 map-specifically, instances of OverlayItem. The overlay handles much of the drawing logic for you. Here are the minimum steps to make this work:

1.  Override ItemizedOverlay<OverlayItem> 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 (e.g., 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 ItemizedOverlay<OverlayItem> {

 private List<OverlayItem> items=new ArrayList<OverlayItem>();

 private Drawable marker=null;

public SitesOverlay(Drawable marker){

super(marker);

this.marker=marker;

items.add(new OverlayItem(getPoint(40.748963847316034,-73.96807193756104),                    "UN", "United Nations"));

 items.add(new OverlayItem(getPoint(40.76866299974387,-73.98268461227417),                    "Lincoln Center", "Home of Jazz at Lincoln Center"));

items.add (new  OverlayItem (getPoint(40.765136435316755,-73.97989511489868),

               "Carnegie Hall", "Where you go with practice, practice, practice"));

items.add(new   OverlayItem(getPoint(40.70686417491799,-74.01572942733765),

               "The Downtown Club", "Original home of the Heisman Trophy"));

populate();}

@Override

protected  OverlayItem createItem(int i) {

return(items.get(i));}

@Override

public void draw(Canvas canvas, MapView mapView, boolean shadow)

 super.draw(canvas, mapView, shadow);

boundCenterBottom(marker);}

@Override

protected boolean onTap(int i) {

Toast.makeText(NooYawk.this,items.get(i).getSnippet(),

Toast.LENGTH_SHORT) .show();

return(true);}

@Override

public int size() {

return(items.size());

} }

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 full-size Google Maps, clicking a pushpin pops up a bubble with information about the business at that pin'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) {

Toast.makeText(NooYawk.this,items.get(i).getSnippet(),

Toast.LENGTH_SHORT).show();

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 built-in overlay to handle two common scenarios:

  • Showing where you are on the map, based on GPS or other location-providing logic
  • Showing where you are pointed, based on the built-in compass sensor, where available

All you need to do is create a MyLocationOverlay instance, add it to your MapView'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 recommended that you enable these features in onResume() and disable them in onPause().

For example, NooYawk will display a compass rose using MyLocationOverlay. To do this, we first need to create the overlay and add it to the list of overlays:

me=new MyLocationOverlay(this, map);

map.getOverlays().add(me);

Then we enable and disable the compass rose as appropriate:

@Override

public void onResume() {

super.onResume();

me.enableCompass();}

@Override

public void onPause(){

super.onPause();

  me.disableCompass();}

The Key to It All

If you actually download the source code for the book, compile the NooYawk project, install it in your emulator, and run it, you will probably see a screen with a grid and a couple of pushpins, but no actual maps.

That's because the API key in the source code is invalid for your development machine. Instead, you will need to generate your own API key(s) for use with your application.

Full instructions for generating API keys for development and production use can be found on the Android web site (http://code.google.com/android/add-ons/google -apis/mapkey.html). In the interest of brevity, let's focus on the narrow case of getting NooYawk running in your emulator. Doing this requires the following steps:

1. Visit the API key signup page and review the terms of service.

2. Reread those terms of service and make really sure you want to agree to them.

3. Find the MD5 digest of the certificate used for signing your debug-mode applications.

4. On the API key signup page, paste in that MD5 signature and submit the form.

5. On the resulting page, copy the API key and paste it as the value of apiKey in your MapView-using layout.

The trickiest part is finding the MD5 signature of the certificate used for signing your debug-mode applications. Actually, much of the complexity is merely in making sense of the concept.

All Android applications are signed using a digital signature generated from a certificate. You are automatically given a debug certificate when you set up the SDK, and there is a separate process for creating a self-signed certificate for use in your production applications. This signature process involves the use of the Java keytool and jar signer utilities. For the purposes of getting your API key, you only need to worry about keytool.

To get your MD5 digest of your debug certificate, if you are on Mac OS X or Linux, use the following command:

keytool -list -alias androiddebugkey –keystore ~/.android/debug.keystore -storepass

android -keypass android

On other development platforms, you will need to replace the value of the –keystore switch with the location for your platform and user account:

  • On Windows XP, use C:\Documents and Settings\<user>\.android\debug. keystore.
  • On Windows Vista/Windows 7, use C:\Users\<user>\.android\debug.keystore (where <user> is your account name).

The second line of the output contains your MD5 digest, as a series of pairs of hex digits separated by colons.

使用MapViewMapActivity显示地图

谷歌地图是谷歌服务中最受欢迎的后台搜索服务之一,它可以让你寻找到一切,比如,从纽约到旧金山 (仅 2,905 英里 !)方向的最近的比萨饼客厅,还提供街道视图和卫星图像。

大多数的安卓设备,都整合了谷歌地图,这并不奇怪。而这样做的目的是,在主要安卓的发射器中有一个能直接对用户有用的显示地图的活动。但作为一个开发者,更多和你有关联的是MapView类和MapActivity类 ,这让地图融入你自己的应用程序中。你不仅可以显示地图,控制缩放级别,让人们平移,而且你也可以在安卓的基于位置的服务的(包括第32章)配合下,显示设备在哪以及往哪里去。

幸运的是,把基本显示功能纳入你的安卓项目是相当容易的。如果你想要获得想象的功能,你也有权利去增加你想象的功能。

条款无情

把谷歌地图纳入你自己的应用程序上一般需要一个相当长的法律术语集。其中包括一些可能使你不愉快的条款。
    如果你正在考虑使用谷歌地图,请严密地审查这些条款来确定你的使用目的是否将无法运行、是否与其它各个条款相抵触。如果有任何潜在冲突的地方,强烈建议您寻求专业的法律条款。
    此外,为了其他显示选项,根据其他地图数据的来源,请睁大你的眼睛去选择。如OpenStreetMap的(http://www.openstreetmap.org/)。

添加项问题

如同安卓l.5版本,谷歌地图不是安卓SDK严格的一部分。相反,它是谷歌应用程序界面的加载项,是普通SDK的延伸部分。安卓附加系统为其他子系统提供了挂钩。这可能是设备一部分而不是设备的全部。

注: 谷歌地图不是安卓开源项目的一部分,由于缺乏一些获得许可的问题有一些设备中并没有谷歌地图。例如,在写这篇文章的时候,人们所用的爱可视5的安卓系统并没有谷歌地图。

大体上,谷歌地图是加载项中的一个事实,这并不影响你日常的开发。然而,牢记以下:

  1. 你将需要创建一个合适的项目指标,以确保谷歌地图的应用程序界面将是可用的。
  2. 为了测试你完成了的谷歌地图,你还需要安卓运行的虚拟环境(AVD) ,支持谷歌地图API。

基本要素 

最简单的方式得到一张地图,为您的应用程序创建自己的类MapActivity 的子类。像 MapActivity ListActivity ,在列表视图中占主导地位的活动背后,它进行了一些活动的包装,处理一些细微之处设立一个由MapView主导的活动。

在你为MapActivity子类设计布局时,你需要添加一个自定义的视图,在写这篇文章时用的是,com.google.android.maps.MapView 。这是普通平凑的方式拼出桌面小插件类的名称,包括完整的软件包名称与类名。这是必要的,因为MapView类是不在com.google.android.widget包中。你可以给你想要的任何MapView类部件的android :id属性赋值,再加上处理所有的布局细节,与你的其它部件正确的呈现出来。

然而,你需要有这两个项目:

  1. android:apiKey ,在创建中,将需要一个Google地图API密钥。
  2. android:clickable="true",如果你想让用户能够点击,并能够平移地图,设置clickable为“真”。

例如,从地图/ NooYawk的示例应用程序,这里是主要的布局:

<?xml version="l.0" encoding="utf-8f'?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

   android:layout height="fill_parent">

  <com.google.android.maps.MapView android:id="@+id/map"

   android:layout_width= fill_parent"

android:layout_height="fill_parent"

   android:apiKey="<YOUR API_KEY>"

   android:clickable="true" />

</RelativeLayout>

在这一章的后面,“关键所在”这一节中,我们将讨论那个神秘API密钥。此外,在你的AndroidManifest.xml文件中,您将需要添加几个额外的东西:

(1)获得网络访问权限和获得应用访问范围(如WIFI)性的定位权限(后者与使用的MyLocationOverlay类,在本章后面介绍)

(2)在你的<application> 中,添加一个<uses-library>元素:
android:name ="com.google.android.maps",表明你正在使用一个可选的Android应用程序接口。

对于初学者这几乎所有的内容你都需要,再加上从你的创建类继承MapActivity类。如果你是闲来无事做,就新建该项目,并把它在模拟器中运行起来,你就会得到一个漂亮的世界地图。但是请注意,那是抽象的 MapActivity 类。您需要调用的是RouteDisplayed()方法表明你是否找到某个导航方向。

在理论上,用户可以在地图上使用方向键。然而,当他们查看整个世界的地图时,这不是十分的有用。

由于世界地图本身做的不是很好,我们需要添加一些东西,如下面的描述。

练习控制

你可以通过findViewById()方法找到你MapView中的部件,就像系统本身部件一样。在桌面插件本身提供了一个getMapController()方法。在MapView 类MapController之间,你有与之相持平的能力来决定地图展示什么以及怎样展示它。以下各节介绍变焦和中心点设置的功能,这些将是你最有可能要使用的特征。

缩放

起初你会觉得世界地图是相当宽广。通常,人们在手机上看地图时都希望什么范围变窄点,如一些城市的楼群。

你可以直接通过setZoom()方法对MapController控制缩放的级别。这里需要传一个整型参数,表示缩放的级别,其中1是对整个世界地图的直接显示和21是最精密的变焦镜头,你可以看到。每一个级别是一倍的有效分辨率:1赤道测量256个像素宽,而21赤道测量268435456像素宽。由于你的手机显示屏可能不会有268435456像素的任何尺寸,用户会看到一个小地图集中在一个小小的角落。 16水平将显示几个街区的城市在每一个层面,这可能是一个合理的起点实验。

如果你期望允许用户更改缩放级别,就调用setBuiltInZoomControls()方法并将参数设置为“真”,用户将能够在地图的底部中心通过控制进行变焦来放大和缩小地图。

居中

通常情况下,你需要对地图显示进行控制,如超出缩放级别,用户的当前位置或与你的活动中的一些数据保存的位置。要改变地图的位置,在MapController中调用setCenter ()方法,在给定的中心点GeoPoint上设置地图视图 。

将GeoPoint作为setCenter()方法的参数 。通过纬度和经度,一个GeoPoint代表一个位置。捕获的是,GeoPoint纬度和经度为整数,代表实际的纬度和经度乘以1e6。

这样就可以节省一点内存与存储单精度浮点型或双精度浮点型数据的位,这在安卓内部大大加快了对地图的一个位置GeoPoint所需要做的一些转换计算。然而,这就意味着你必须记住由le6乘以现实世界的经度和纬度。

地形起伏 

正如你在你的全屏电脑上使用谷歌地图服务一样可以显示卫星图像。这在安卓手机地图一样可以实现。

MapView类中提供toggleSatellite()方法,其中,顾名思义,从显示区域进行切换或者关闭卫星的角度查看。你可以让用户通过选项菜单或触发按下监听事件进行切换,在项目NooYawk中,设置按键按下事件方法用onKeyDown()方法。

层上加层 

如果你曾经使用过的全尺寸版本的谷歌地图,你可能看到地图本身上面覆盖的东西,如指示附近被搜索的企业的位置图钉。在地图界的说法( 和,对于这个问题,在许多严谨的图形编辑器都有),该图钉与图层分开的地图本身比,你看到的是图层上面的图钉层组成的独立层。

安卓的地图显示允许你创建层为好,这样你可以在你的地图上做标记,正如在你的应用程序中你需要根据用户输入目的地进行选择。例如,NooYawk项目中使用一个图层显示选择的建筑物位于曼哈顿岛。

Overlay

要对任何地图添加覆盖,需要作为一个子类进行覆盖。如果你正在寻找添加图钉或类似的子类进行覆盖的话,有一个可用ItemizedOverlay子类,ItemizedOverlay简化了这一过程。

附加一个覆盖类到你的地图,我们在这里做一个自定义SitesOverlay 类,只需通过实例对象调用你的MapView类中getOverlays()方法和add()方法进行覆盖。

我们将在下一节细看该标记。

绘制ItemizedOverlay 

顾名思义,在ItemizedOverlay中允许你提供的兴趣点列表上显示地图,具体而言,新建一个OverlayItem实例。为你覆盖处理大部分绘制逻辑。下面是这项工作最基本的步骤:

1. 覆盖ItemizedOverlay <OverlayItem>作为自己的子类(在本文这个例子中用的名字是 SitesOverlay )。

2. 在构造函数中,创建你项目中OverlayItem类的对象,并调用populate()方法,他们这是准备用于覆盖的。

  1. 实现size()方法返回被覆盖处理的项目数。
  2. 覆盖createItem()方法返回索引的OverlayItem对象。

5. 当你Itemizedoverlay类实例化对象,它提供一个图像表示默认图标(例如,一个图钉)显示为每个项目。

由NooYawk构造的标记是可绘制用于第5步。它显示一个图钉。

您可能还希望做一个更好的工作覆盖draw()方法来处理标记的阴影。而你将处理地图上的标记的影子,看来你需要提供一点援助,才知道图标的底部,所以可以得出适当绘制阴影。

处理屏幕单击事件

子类也可以覆盖实现onTop()方法 ,当用户点击地图时得到通知,所以可以调整对它的绘制覆盖。例如,在全尺寸的“谷歌地图”中,点击一个图钉弹出一个与图钉针尖的位置相关的信息。与onTop()方法类似 ,在安卓中你可以做很多类似的设置。

onTop()方法是ItemizedOverlay收到的被点击OverlayItem的事件处理。带着这些事件,这取决你来做一些值得事情。

在SitesOverlay的情况,如前一节中所示,onTop()方法看起来像这样:

protected boolean onTap(int i) {

Toast.makeText(NooYawk.this, items.get(i).getSnippet(),Toast.LENGTH_SHORT).show();

return(true),}

在这里,我们只是设置了一个简短的片段从OverlayItem上弹出式显示,返回真值,表示我们处理的响应器。

MyLocationOverlay

安卓有一个内置的叠加处理有两种常见的情景:

  • 1)Gps显示你在地图上或其他位置提供逻辑基础。
  • 2)显示你在哪里标记,其中根据内置可用的罗盘传感器。

所以您需要做的就是创建一个MyLocationOverlay类的实例化对象,将它添加到您的MapView类的覆盖列表,在适当的时候,启用和禁用所需的功能,“在适当的时刻”的概念是电池最长使用时间。有没有暂停时更新位置或方向的活动方法,所以建议你用onResume ()方法在启用这些功能,并禁止他们时使用onPause ()方法 。

例如,在NooYawk项目MyLocationOverlay将显示一个罗盘使用。要做到这一点,我们首先需要创建一个对象添加实现覆盖方法,并把它添加到列表中:

me=new MyLocationOverlay(this, map);

map.getOverlays().add(me);

然后我们用onResume()方法和onPause()方法启用和关闭罗盘:

关键所在

如果你已经下载了本书的源代码,并编译NooYawk项目,把上它安装在你的模拟器中,并运行该项目,你可能会看到一个网格屏幕和一个图钉,但没有实际的地图。

这是因为在源代码中的API密钥在你的开发机器上是无效的。相反,你需要生成你自己的API密钥(S)使用在你的应用程序中。

可以发现在安卓的网站(http://code.google.com/android/add-ons/google-apis/ mapkey.html)上有开发和生产使用的API密钥生成的完整说明。在简洁起见,让我们更专注于狭窄的情况下获得NooYawk项目在模拟器上运行所需的密钥。这样做需要以下步骤:

  • 1)访问的API密钥的注册页面,并查看服务条款。
  • 2)重读这些服务条款,让你确定你是否真的确定要同意他们的条款。

(3)找到MD5摘要签署调试模式的应用程序使用的证书。

(4)API密钥的注册页面上,粘贴在该MD5签名并提交表格。

  • 5)在结果页上,复制的API密钥,将其粘贴在您的MapView使用布局的  apiKey的值上。

最棘手的部分是找到MDS签名用于签名的证书的调试应用程序。事实上,许多复杂的事情仅仅是在意义上的概念。

所有的安卓应用程序都使用数字签名生成证书。当您设置你的SDK时会自动给出一个调试证书 ,并有一个单独的进程,创建了在开发应用程序中使用自签名的证书。这个签名的过程中涉及使用的密钥和证书管理工具和JDK中包含的用于JAR文件签名和验证的工具公共的工具。这些的宗旨就是,你只需要担心你的密钥就可以了。

你的调试证书的MD5摘要,如果你的电脑是苹果操作系统(Mac OS X)或Linux ,使用下面的命令:

keytool -list -alias androiddebugkey –keystore ~/.android/debug.keystore -storepass

 android -keypass android

在其他开发平台上,您将需要更换你的平台和用户的密钥的位置:

 (1) 在Windows XP操作系统中,使用命令C:\文件和设置\ <用户> \android 根 目录\ debug.keystore 。
  (2) 在Windows Vista / Windows 7操作系统在中,使用C:\用户\ <user> \android根目录\ debug.keystore(<user>是您的账户名)。

输出的第二行就包含你的MD5的摘要,由冒号分隔的一系列十六进制数字对作为一个MD5。


免费下载 ×

下载APP,支持永久资源免费下载

下载APP 免费下载
温馨提示
请用电脑打开本网页,即可以免费获取你想要的了。
扫描加我微信 ×

演示

×
登录 ×


下载 ×
论文助手网
论文助手,最开放的学术期刊平台
							 
回复
来来来,吐槽点啥吧

作者联系方式

×

向作者索要->