Android Baidu map SDK v3.0.0 (1) and androidv3.0.0

Source: Internet
Author: User

Android Baidu map SDK v3.0.0 (1) and androidv3.0.0

Reprinted please indicate the source: http://blog.csdn.net/lmj623565791/article/details/37729091

Recently, my company wanted to integrate Baidu map into a project. So I studied Baidu map SDK for one day. The current version is Android SDK v3.0.0. Although Baidu map has a lot of related code on the Internet, most of them may be old versions, and Baidu map API changes are also relatively large, I would like to share with you the success of the day.

The functions described in the blog are as follows:

1. Features

A. You must first import the map, and then switch the map mode to common, satellite, and real-time traffic.

B. Locate the current location.

:


C. dynamically Add a cover, click the cover, and the pop-up layer and other effects are displayed.

:



D. Use a direction sensor to add a direction to the map's positioning function. I am crazy about it, regardless of the southeast or northwest. Therefore, this function is very important for me and the mobile phone keeps rotating, only in this way can I know which path to take. It is useless for me to directly display the map.

(My 360-degree rotating mobile phone, observed changes ):



Switching to another mode is also amazing:


E. Provides offline map download, which greatly saves user traffic and ensures map usage without network conditions.

Basically, this is the first article about the above functions. We should first import Baidu map into the app.

2. Apply for a key

A, apply for a key, to Baidu API console page: http://lbsyun.baidu.com/apiconsole/key


Enter the name of the application, select the application type, and enter security.

B. Obtain the security code (digital signature; package name:

Open IDE:

The black box contains a digital signature, and the package name is the package name of our application, which is directly connected by a semicolon: for example, F5: 10: 39: D9: 81: 57: BD: 2E: A0: CD: E3: EB: 5E: C4: CC: E0: E0: 0D: 41: 56; com. zhy. zhy_baidu_ditu_demo03

Click Finish to get the key:



3. The first baidu map application

You can simply click Download on the official website and select the download option. I will post the source code later.

Configuration:

Step 1: Create a libs folder in the project, copy the baidumapapi_vX_X_X.jar in the development package to the libs root directory, and copy libBaiduMapSDK_vX_X_X.so to the libs \ armeabi directory (the two files are already available in, if you want to integrate it into your own project, you need to add it yourself.) The copied project directory is shown in;

Note: liblocSDK3.so and locSDK_3.1.jar are resources used by Baidu positioning SDK. developers can add them as needed.
Android_dev1.png
Step 2: Select Add External JARs in Project Properties> Java Build Path> Libraries, select baidumapapi_vX_X_X.jar, and return.
After the preceding two steps, you can use all the functions provided by Baidu map SDK.
Note: Due to the adt plug-in upgrade, if you use Eclipse adt 22, you need to set the development environment as follows:
1) In Eclipse, right-click the project and choose Properties> Java Build Path> Order and Export to make Android Private Libraries check;
2). Project-> clean all.


A. Add a development Key to the application.

<Application <meta-data android: name = "com. baidu. lbsapi. API_KEY" android: value = "Developer key"/> </application>


B. Add required permissions

<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" /> <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.BROADCAST_STICKY" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />


C. Add a map control to the layout file.


<com.baidu.mapapi.map.MapViewandroid:id="@+id/id_bmapView"android:layout_width="fill_parent"android:layout_height="fill_parent"android:clickable="true" />


D. initialize the Context global variable referenced by the SDK when the application is created:

@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); // initialize the context information before using the SDK components, and pass in the ApplicationContext // note that this method must be implemented before the setContentView method. initialize (getApplicationContext (); setContentView (R. layout. activity_main );}


Okay. The map will be displayed after these four steps ~~

E. However, the map consumes a lot of power, so it is necessary to manage its claim cycle.

Package com. zhy. zhy_baidu_ditu_demo00; import android. app. activity; import android. OS. bundle; import android. view. window; import com. baidu. mapapi. SDKInitializer; import com. baidu. mapapi. map. mapView; public class MainActivity extends Activity {private MapView mMapView = null; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); requestWindowFeature (Window. FEATURE_NO_TITLE); // initialize the context information before using the SDK components, and pass in the ApplicationContext // note that this method must be implemented before the setContentView method. initialize (getApplicationContext (); setContentView (R. layout. activity_main); // obtain the map control reference mMapView = (MapView) findViewById (R. id. id_bmapView) ;}@ Overrideprotected void onDestroy () {super. onDestroy (); // execute mMapView when onDestroy is executed in activity. onDestroy () to implement mMapView for map lifecycle management. onDestroy (); mMapView = null;} @ Overrideprotected void onResume () {super. onResume (); // execute mMapView when onResume is executed in the activity. onResume () to implement mMapView for map lifecycle management. onResume () ;}@ Overrideprotected void onPause () {super. onPause (); // execute mMapView when onPause is executed in activity. onPause () enables mMapView for map lifecycle management. onPause ();}}


All right, complete. In fact, the developer guide for Baidu is very clear about helloworld ~~~~



Download source code




Android uses Baidu map sdk to display no map on the machine

No error is reported during running, but only the square is displayed. It is a key problem ..
Or you can download the demo provided by Baidu and run it.

To call Android Baidu map SDK21 to locate nullpointerexception in SDK33

MLocClient. registerLocationListener (myListener );
Register a listener

Related Article

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.