Android calls Baidu api to obtain latitude and longitude and map demo

Source: Internet
Author: User

When you use Baidu api to obtain the current longitude and latitude, you can use the api demo with the same code, but the error BMapManager cannot be instantiated.

This is written in the 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;

// Baidu MapAPI management class
BMapManager mBMapMan = null;

// Authorization Key
// Address: http://developer.baidu.com/map/android-mobile-apply-key.htm
String mStrKey = "E411350F624D8D13522D964224B5B960950BE7B2 ";
Boolean m_bKeyRight = true; // The Authorization Key is correct and passes verification.

// Common event listening, used to handle common network errors, authorization verification errors, etc.
Static class MyGeneralListener implements MKGeneralListener {

Public void onGetNetworkState (int iError ){
Log. d ("MyGeneralListener", "onGetNetworkState error is" + iError );
Toast. makeText (BMapApp. mDemoApp. getApplicationContext (), "your network has an error! ",
Toast. LENGTH_LONG). show ();
}


@ Override
Public void onGetPermissionState (int iError ){
Log. d ("MyGeneralListener", "onGetPermissionState error is" + iError );
If (iError = MKEvent. ERROR_PERMISSION_DENIED ){
// Authorization Key error:
Toast. makeText (BMapApp. mDemoApp. getApplicationContext (),
"Enter the correct authorization Key in the BMapApiDemoApp. java file! ",
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 ());
// The map sdk is initialized successfully and the location listening time is set.
If (isSuccess ){
MBMapMan. getLocationManager (). setpolicyinternal (10, 5 );
}
Else {
// Map sdk initialization failed. You cannot use the sdk
}
Super. onCreate ();
}


@ Override
// Call the destroy () function of mapadpi before your app exits to avoid time consumption caused by repeated initialization.
Public void onTerminate (){
// TODO Auto-generated method stub
If (mBMapMan! = Null ){
MBMapMan. destroy ();
MBMapMan = null;
}
Super. onTerminate ();
}
}

 

 

The focus is on the red sentence. In this case, I cannot find this object. I thought there was a problem with the package. How many times have the so file been imported? The so file has also been exported...

Write mBMapMan = new BMapManager (getApplicationContext ());

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.