Android地图应用使用文档

Android地图应用使用文档

主程序
public class actMap extends MapActivity {
/** Called when the activity is first created. */
MapView mapView,myMapView;
MapController mapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Log.d("--i8i--","Start");
setContentView(R.layout.main);
//get the element of mapView as an object
mapView = (MapView) findViewById(R.id.map);
//get the element of zoom as an object
ViewGroup zoom=(ViewGroup)findViewById(R.id.zoom);
//apply zoom function
zoom.addView(mapView.getZoomControls());

//set a controller
mapController = mapView.getController();
//set the mode for the view
//there are 3 modes --- setStreetView, setSatellite,setTraffic
mapView.setStreetView(true);
mapController.setZoom(15);
//set the location point
updateView();
}

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}

private void updateView(){
//set latitude
Double lat = 31.23717*1E6;
//set longitude
Double lng = 121.50811*1E6;

GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());
//mapController.animateTo(point);
mapController.setCenter(point);
}

}

Layout / main.xml中添加MapView控件
MapView控件无法在图形界面里通过+号图标来Add a new element
因此,我们直接在代码中添加MapView控件
<com.google.android.maps.MapView android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0fAMSn0EFVhfy2cnpHlPIFpWgTgBzeUON6lms7w "
android:clickable="true" />
唯一注意的一点是,apiKey是Google使用的一个授权key,只有当程序员提供自己机器的MD5编号后,提交给Google,Google才会给你一个唯一的apiKey。详见:http://code.google.com/android/toolbox/apis/mapkey.html

获得apiKey
1. 进入cmd

2. 进入keystore目录
Windows Vista: C:\Users\<user>\AppData\Local\Android\debug.keystore
Windows XP: C:\Documents and Settings\<user>\Local Settings\Application Data\Android\debug.keystore
OS X and Linux: ~/.android/debug.keystore
如公司机器为:
D:\Profiles\BFM347\Local Settings\Application Data\Android
则C:\Users\<user>> cd D:\Profiles\BFM347\AppData\Local\Android"

3. 输入命令来产生一个MD5编号
keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android

4. 注册apiKey
将你的MD5 网上注册,前提是需注册一个google用户
http://code.google.com/android/maps-api-signup.htmlhttp://code.google.com/android/maps-api-signup.html

5. 在main.xml中的apiKey处,添加获得的apiKey

P.S. 如果还有什么不清楚的 可参考
http://groups.google.com/group/android-developers/browse_thread/thread/38545a723378005f/2a45dfc1d8329fcd?show_docid=2a45dfc1d8329fcd

AndroidManifest.xml设置
在这个文件里 要添加一个授权说明
将以下三句插在<application android:icon=….>标签前
<!-- Permissions -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

如:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.michaelhuebl.android"
android:versionCode="1"
android:versionName="1.0.0">

<!-- Permissions -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

<application android:icon="@drawable/icon" android:label="@string/app_name">

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

参考网站
http://www.anddev.org/viewforum.php?f=18
这是一个不错的国外论坛的子论坛,里面是专门针对Map开发的应用,而且大多数的程序作者提供源码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值