Android的Google地图开发
来源:互联网 发布:鸭鸭网络 编辑:程序博客网 时间:2024/05/18 05:45
编写这个程序之前需要有一个Google地图扩展库在SDK中,一般来说,android 1.5中就已经有了。如果没有的话可以在这里下载:
http://code.google.com/android/add-ons/google-apis
这个插件要求android 1.5或者更高的版本。下载后按照自己的环境做相应的调整。
第一步:先建立新的activity名字叫AndroidMapView;
第五步:打开Java文件。即AndroidMapView.java文件。在这个activity中我们继承了一个特别的类叫做:MapActivity 。
因此将程序开头改成如下形式:
public class AndroidMapView extends MapActivity {
第六步:这里需要一个名叫isRouteDisplayed()的方法,这个方法是必须的。用来获取地图API密匙,一旦获得就会传给上边提到的apiKey这个变量。
Android中提供了一个叫ZoomControls的控件对地图来进行放大和缩小处理。
第七步:回到配置文件中来,我们需要一个新的ViewGroup布局器来放置ZoomControls这个控件。
第八步:回到AndroidMapView.java文件中。
第九步: onCreate()在这个方法中将第八部中定义的变量全部初始化。
第十步:将控件ZoomControls添加到LinearLayout中去。
main.xml文件的源码
AndroiMaifest.xml文件的源码
转贴:http://www.pin5i.com/showtopic-android-google-maps-development.html
http://code.google.com/android/add-ons/google-apis
这个插件要求android 1.5或者更高的版本。下载后按照自己的环境做相应的调整。
第一步:先建立新的activity名字叫AndroidMapView;
第二步:因为我是用的是Google的地图库,而非Android标准库。所以我们先要在AndroidManifest.xml文件<application>中作出声明。
<uses-library android:name="com.google.android.maps" />第三步:以为这个程序需要实时的从Google地图库中读取信息,所以添加接入Internet权限。在<manifest>中声明:
<uses-permission android:name="android.permission.INTERNET" />第四步:现在主要的配置文件都已经开放给我们。定义一个layout给com.google.android.maps.MapView其中包括android.widget.RelativeLayout :
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainlayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.google.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="Your Maps API Key" /></RelativeLayout>Clickable属性决定了用户能否和地图之间进行互动。一次设置成TRUE。apiKey属性中包含了Google地图API密钥,由于MapView使用的是Google地图数据,在此主要是为了获得地图数据。
第五步:打开Java文件。即AndroidMapView.java文件。在这个activity中我们继承了一个特别的类叫做:MapActivity 。
因此将程序开头改成如下形式:
public class AndroidMapView extends MapActivity {
第六步:这里需要一个名叫isRouteDisplayed()的方法,这个方法是必须的。用来获取地图API密匙,一旦获得就会传给上边提到的apiKey这个变量。
Android中提供了一个叫ZoomControls的控件对地图来进行放大和缩小处理。
第七步:回到配置文件中来,我们需要一个新的ViewGroup布局器来放置ZoomControls这个控件。
<LinearLayout android:id="@+id/zoomview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/mapview" android:layout_centerHorizontal="true"/>
第八步:回到AndroidMapView.java文件中。
LinearLayout linearLayout;MapView mapView;ZoomControls mZoom;
第九步: onCreate()在这个方法中将第八部中定义的变量全部初始化。
linearLayout = (LinearLayout) findViewById(R.id.zoomview);mapView = (MapView) findViewById(R.id.mapview);mZoom = (ZoomControls) mapView.getZoomControls();
第十步:将控件ZoomControls添加到LinearLayout中去。
linearLayout.addView(mZoom);
第十一步:到这我们就可以运行这个程序了。
需要注意的是红色字体部分,很有肯能忘记了填写apikey。如果没有可以参照这一篇《Android开发如何利用Google Maps》自己申请一个。
AndroidMapView.java文件的源码
package android.mapview;import android.os.Bundle;import android.widget.LinearLayout;import android.widget.ZoomControls;import com.google.android.maps.MapActivity;import com.google.android.maps.MapView;public class AndroidMapView extends MapActivity { /** Called when the activity is first created. */ LinearLayout linearLayout; MapView mapView; ZoomControls mZoom; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); linearLayout = (LinearLayout) findViewById(R.id.zoomview); mapView = (MapView) findViewById(R.id.mapview); mZoom = (ZoomControls) mapView.getZoomControls(); linearLayout.addView(mZoom); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; }}
main.xml文件的源码
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainlayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.google.android.maps.MapView android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="your api key" /><LinearLayout android:id="@+id/zoomview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/mapview" android:layout_centerHorizontal="true"/></RelativeLayout>
AndroiMaifest.xml文件的源码
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android.mapview" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/map" android:label="@string/app_name"> <uses-library android:name="com.google.android.maps" /> <activity android:name=".AndroidMapView" 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-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.INTERNET" /> </manifest>
转贴:http://www.pin5i.com/showtopic-android-google-maps-development.html
- Android的Google地图开发
- android开发google地图
- android Google地图开发
- Android开发之Google地图开发
- Android基于LBS的地图开发:(一)Google地图的调用
- Android开发--使用Google地图(Map View)
- android学习---开发Google地图应用程序
- android手机google地图开发时与实际地图上经纬度的转换问题
- google地图开发(Google Maps Android API V2 的相关问题解决)
- Google地图的应用开发分析
- 适用的Google地图开发-简单版
- 开发Google地图应用程序
- google地图开发心得
- Google地图开发总结
- google 地图开发记录
- Google地图开发API
- 编写android对google地图的调用
- 编写android对google地图的调用
- Qt自定义信号和槽
- 日本房产泡沫的崩塌,虽然很长,希望80后仔细阅读
- C语言学生信息管理系统(动态链表版)
- Android's HTTP Clients
- delphi 发送Windwos消息控制按钮
- Android的Google地图开发
- 深入理解php底层:php生命周期
- devexpress progressBarControl的使用
- 从那一天起,你就成了我的全部
- 一个日历方法
- java上传文件路径问题
- win7回收站恢复方法
- 对于单cpu中断的理解
- vi 可视模式