在使用百度api擷取當前經緯度的時候,使用api demo,代碼一模一樣,可就是報錯BMapManager這玩意沒法執行個體化,坑我呀
demo上是這麼寫的:
package com.stgmobile.cyt.activity.enterprise;
import android.app.Application;
import android.util.Log;
import android.widget.Toast;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKEvent;
import com.baidu.mapapi.MKGeneralListener;
public class BMapApp extends Application {
static BMapApp mDemoApp;
//百度MapAPI的管理類
BMapManager mBMapMan = null;
// 授權Key
// 申請地址:http://developer.baidu.com/map/android-mobile-apply-key.htm
String mStrKey = "E411350F624D8D13522D964224B5B960950BE7B2";
boolean m_bKeyRight = true;// 授權Key正確,驗證通過
// 常用事件監聽,用來處理通常的網路錯誤,授權驗證錯誤等
static class MyGeneralListener implements MKGeneralListener {
public void onGetNetworkState(int iError) {
Log.d("MyGeneralListener", "onGetNetworkState error is "+ iError);
Toast.makeText(BMapApp.mDemoApp.getApplicationContext(), "您的網路出錯啦!",
Toast.LENGTH_LONG).show();
}
@Override
public void onGetPermissionState(int iError) {
Log.d("MyGeneralListener", "onGetPermissionState error is "+ iError);
if (iError == MKEvent.ERROR_PERMISSION_DENIED) {
// 授權Key錯誤:
Toast.makeText(BMapApp.mDemoApp.getApplicationContext(),
"請在BMapApiDemoApp.java檔案輸入正確的授權Key!",
Toast.LENGTH_LONG).show();
BMapApp.mDemoApp.m_bKeyRight = false;
}
}
}
@Override
public void onCreate() {
Log.v("BMapApp", "onCreate");
mDemoApp = this;
mBMapMan = new BMapManager(this);
boolean isSuccess = mBMapMan.init(this.mStrKey, new MyGeneralListener());
// 初始化地圖sdk成功,設定定位監聽時間
if (isSuccess) {
mBMapMan.getLocationManager().setNotifyInternal(10, 5);
}
else {
// 地圖sdk初始化失敗,不能使用sdk
}
super.onCreate();
}
@Override
//建議在您app的退出之前調用mapadpi的destroy()函數,避免重複初始化帶來的時間消耗
public void onTerminate() {
// TODO Auto-generated method stub
if (mBMapMan != null) {
mBMapMan.destroy();
mBMapMan = null;
}
super.onTerminate();
}
}
重點在紅色那句話上,這樣寫怎麼也找不到這個對象 ,以為包有問題,導了多少次了,so檔案也導了 可惡。。。
要這麼寫mBMapMan = new BMapManager(getApplicationContext());