Android软件中嵌入地图之二:百度地图
Android 软件中嵌入地图之二:百度地图
#移动开发 #Android
百度地图
一、当前版本:v2.2.1,支持 Android 2.1 及以上版本
二、使用方法:
1 申请密钥:通过应用名称和简单介绍生成密钥
[http://developer.baidu.com/map/android-mobile-apply-key.htm
](http://developer.baidu.com/map/android-mobile-apply-key.htm)
2 加入库
下库开发包,将其中的 jar 和 so 导入工程
3 修改 AndroidManifest.xml
** <supports-screens **
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" / >
**
**
**
** <uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE" /> **
** <uses-permissionandroid:name="android.permission.CHANGE_WIFI_STATE" /> **
** <uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
**
** <uses-permissionandroid:name="android.permission.READ_PHONE_STATE" /> **
** <uses-permissionandroid:name="android.permission.CALL_PHONE" /> **
**
**
** <permissionandroid:name="android.permission.BAIDU_LOCATION_SERVICE" /> **
** <uses-permissionandroid:name="android.permission.BAIDU_LOCATION_SERVICE" />
**
**
**
** <uses-permissionandroid:name="android.permission.ACCESS_MOCK_LOCATION" />
**
** <uses-permissionandroid:name="android.permission.ACCESS_GPS" /> **
4 修改 layout 中的 xml
** **
** <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" **
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
** <com.baidu.mapapi.map.MapView **
android:id="@+id/bmapsView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" / >
** **
5 修改 Activity.java
import android.app.Activity;
import android.os.Bundle;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.MapController;
import com.baidu.mapapi.map.MapView;
importcom.baidu.platform.comapi.basestruct.GeoPoint;
public class BaiduMapActivity extendsActivity {
BMapManagermBMapMan = null;
MapViewmMapView = null;
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBMapMan= new BMapManager(getApplication());
mBMapMan.init(" 申请的密钥 ", null);
setContentView(R.layout.activity_baidu);
mMapView= (MapView) findViewById(R.id.bmapsView);
mMapView.setBuiltInZoomControls(true);
MapControllermMapController = mMapView.getController();
GeoPointpoint = new GeoPoint((int) (39.915 * 1E6),
(int)(116.404 * 1E6));
mMapController.setCenter(point);
mMapController.setZoom(12);
}
@Override
protectedvoid onDestroy() {
mMapView.destroy();
if(mBMapMan!= null) {
mBMapMan.destroy();
mBMapMan= null;
}
super.onDestroy();
}
@Override
protectedvoid onPause() {
mMapView.onPause();
if(mBMapMan!= null) {
mBMapMan.stop();
}
super.onPause();
}
@Override
protectedvoid onResume() {
mMapView.onResume();
if(mBMapMan!= null) {
mBMapMan.start();
}
super.onResume();
}
}
三、相关链接
[http://developer.baidu.com/map/sdk-android.htm
](http://developer.baidu.com/map/sdk-android.htm)