当前位置: 代码迷 >> Android >> Android开发-使用Googlemap(Map View)
  详细解决方案

Android开发-使用Googlemap(Map View)

热度:35   发布时间:2016-05-01 17:32:10.0
Android开发--使用Google地图(Map View)
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:使用Google地图(Map View)

* 作 者: 雷恒鑫
* 完成日期: 2012 年 08 月 12 日
* 版 本 号: V1.0
* 对任务及求解方法的描述部分
* 输入描述:
* 问题描述:
* 程序输出:

* 程序头部的注释结束

*/

①Google地图的组成元素:地图模型、地图展示、地图控制。

②创建新项目,如下图所示:

 

 

注意:Google Map API属于Google私有API的部分,因此在选择Build Target时需选“Google APIs”选项。

 

③定义目录中的“AndroidMainfest”列表文件,添加以下内容,如下图所示:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.demo.android.twstation"      android:versionCode="1"      android:versionName="1.0">    <uses-sdk android:minSdkVersion="3" />    <application android:icon="@drawable/icon" android:label="@string/app_name">    <uses-library android:name="com.google.android.maps"/>        <activity android:name=".TrainStation"                  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>    <uses-permission android:name="android.permission.INTERNET"></uses-permission></manifest>


 

④定义XML资源文件:

打开“res/layout/main.xml”文件,修改后如图所示:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    ><com.google.android.maps.MapViewandroid:id="@+id/map"android:layout_width="fill_parent"android:layout_height="fill_parent"android:apiKey="此处填入申请到的开发密钥(API Key)"android:clickable="true"/></LinearLayout>

 

⑤产生地图:

打开“src/com/demo/android/twstation/TrainStation.java”文件,修改后程序代码如下:

package com.demo.android.twstation;import android.os.Bundle;import com.google.android.maps.MapActivity;;public class TrainStation extends MapActivity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);    }    @Override    protected boolean isRouteDisplayed(){    	//TODO Auto-generated method stub    	return false;    }}


运行结果:

 

  相关解决方案