百度地图

一、当前版本:v2.2.1,支持Android 2.1及以上版本

二、使用方法:

1          申请密钥:通过应用名称和简单介绍生成密钥
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-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

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

   <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" />

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

 

   <permissionandroid:name="android.permission.BAIDU_LOCATION_SERVICE" />

 

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

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

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

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

4          修改layout中的xml

<?xml version="1.0"encoding="utf-8"?>

<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" />

</LinearLayout>

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

 

posted on 2013-07-24 11:40  xieyan0811  阅读(35)  评论(0编辑  收藏  举报