開發手機地圖(有圖有真相有代碼)

來源:互聯網
上載者:User

申請key:

package com.baidu.mapapi.demo;import android.app.Application;import android.util.Log;import android.widget.Toast;import com.baidu.mapapi.*;public class BMapApiDemoApp extends Application {static BMapApiDemoApp mDemoApp;//百度MapAPI的管理類BMapManager mBMapMan = null;// 授權Key// TODO: 請輸入您的Key,// 申請地址:http://dev.baidu.com/wiki/static/imap/key/String mStrKey = "請輸入您的Key";boolean m_bKeyRight = true;// 授權Key正確,驗證通過// 常用事件監聽,用來處理通常的網路錯誤,授權驗證錯誤等static class MyGeneralListener implements MKGeneralListener {@Overridepublic void onGetNetworkState(int iError) {Log.d("MyGeneralListener", "onGetNetworkState error is "+ iError);Toast.makeText(BMapApiDemoApp.mDemoApp.getApplicationContext(), "您的網路出錯啦!",Toast.LENGTH_LONG).show();}@Overridepublic void onGetPermissionState(int iError) {Log.d("MyGeneralListener", "onGetPermissionState error is "+ iError);if (iError ==  MKEvent.ERROR_PERMISSION_DENIED) {// 授權Key錯誤:Toast.makeText(BMapApiDemoApp.mDemoApp.getApplicationContext(), "請在BMapApiDemoApp.java檔案輸入正確的授權Key!",Toast.LENGTH_LONG).show();BMapApiDemoApp.mDemoApp.m_bKeyRight = false;}}}@Override    public void onCreate() {Log.v("BMapApiDemoApp", "onCreate");mDemoApp = this;mBMapMan = new BMapManager(this);mBMapMan.init(this.mStrKey, new MyGeneralListener());mBMapMan.getLocationManager().setNotifyInternal(10, 5);//if (mBMapMan != null) {//mBMapMan.destroy();//mBMapMan = null;//}super.onCreate();}@Override//建議在您app的退出之前調用mapadpi的destroy()函數,避免重複初始化帶來的時間消耗public void onTerminate() {// TODO Auto-generated method stubif (mBMapMan != null) {mBMapMan.destroy();mBMapMan = null;}super.onTerminate();}}

註冊帳號百度帳號,申請key

資源:

http://download.csdn.net/detail/jingwen3699/4447494

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.