android学习笔记之GoogleMap 【转】

来源:互联网 发布:自动填写验证码软件 编辑:程序博客网 时间:2024/04/27 15:48

GoogleMap介绍

1、Google提供了一组API,可以很方便的在应用程序当中添加基于地图的功能

2、Android将大部分的地图功能封装在MapView当中

3、MapView将通过GoogleMaps服务取得数据,并以地图的方式显示出来

4、MapView提供了一组控件用于地图的控制

 

 

获取Maps API Key(一)

应用程序签名:

1、Android系统要求所有应用程序都必须使用证书进行签名

2、在证书当中包含一个唯一的key

3、证书用于标示应用程序的作者

4、在开发和调试的过程的当中可以使用debug key(C:\Users\<user>\.andriod\debug.keystore)

 

获取Maps APIKey(二)

Debug Key的相关参数:

Keystore name: “debug.keystore”

Keystore password: “android”

Key alias: “androiddebugkey”

Key password: “ android”

CN: “CN=Android Debug,O=Android,C=US”

 

获取Maps APIKey(三)

申请Google MapsAPI Key:

1、生成证书指纹:

2、打开http://code.google.com/intl/zh-CN/android/maps-api-signup.html,输入上面的认证指纹,得到密钥:0O5eD1kV9shMg3crOS_pWL_pXONMv8ss4b19oTQ

<com.google.android.maps.MapView
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:apiKey="0O5eD1kV9shMg3crOS_pWL_pXONMv8ss4b19oTQ"
                 />

 

创建一个MapView

1、创建项目,“built target”选择“Google Inc 2.3.3”

2、创建一个Activity,继承MapActivity

3、在布局文件当中添加如下控件:

<com.google.android.maps.MapView

                android:layout_width="fill_parent"

                 android:layout_height="fill_parent"

                 android:enabled="true"

                 android:clickable="true"

                 android:apiKey="0O5eD1kV9shMg3crOS_pWL_pXONMv8ss4b19oTQ"

              />

5、在AndroidManifest.xml文件中需要添加以下库和权限:

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

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

 

 

在地图当中使用标记的步骤:

1、在MapView之上创建一个单独的图层Overlay

2、创建标记对象

3、将标记显示在指定图层的指定位置

4、处理点击标记的事件

 

Overlay的作用

1、一个Overlay对象就代表了显示在MapView之上的图层

2、在一个Overlay当中可以包含多个地图标记

 

ItemizedOverlay的作用

1、ItemizedOverlay是Overlay的子类

2、在该类当中持有一个或者多个OverlayItem

3、每一个OverlayItem代表一个标记


原创粉丝点击