Android studio Baidu map development (1) Configure projects and display maps

Source: Internet
Author: User

Android studio Baidu map development (1) Configure projects and display maps

Android studio Baidu map development (1) Configure projects and display maps

Email: chentravelling@163.com

Recently I was learning to write an app and needed Baidu map. So I sorted out an entry-level document for reference only.

Development Environment: win7 64-bit,Android Studio, Please note that it is Android Studio.

1. Obtain Baidu map API key

The first step: in Baidu map LBS open platform registered as Baidu developers: http://lbsyun.baidu.com/apiconsole/key

Step 2: Create an application

Package name: manifest label;

SHA1 Acquisition Method:

① IDE is used to obtain Android Studio

Step 3 enter the keystore password: Press ENTER

So we can get the SHA1 code.

② IDE is Eclipse or MyEclipse

[Excerpt: http://blog.csdn.net/crazy1235/article/details/41014603]

1. Method 1: Use eclipse to view details.

Open the preferences menu of eclipse, and you can see the value of SHA1 in [Build] Under Android, such:

2. Method 2: Use the keytool (built-in jdk) to view data.

In the console, enter [cd. android, and then enter keytool-list-v-keystore debug. keystore: Press enter. Then, you are prompted to enter the key library password. Enter android and press enter to display the value of SHA1.

You can obtain the API Key after submission.

2. Download Baidu map SDK

: Http://lbsyun.baidu.com/index.php? Title = androidsdk/sdkandev-download

3. Add the SDK to the Project

[For myeclipse and eclipse, put both jar and. so files in the libs folder under the project directory]

1. Copy the jar package in Baidu map SDK to the libs folder under the project directory.

2. Right-click all jar packages and choose add as library> OK.

3. create a folder in the src/main/directory to store the folder. so file [copy the v8a, v7a, and abi folders; otherwise, an error occurs: No implementation found for long com. baidu. platform. comjni. map. commonmemcache. JNICommonMemCache. create]

4. Use Baidu Map

From Baidu Official Website: http://lbsyun.baidu.com/index.php? Title = androidsdk/guide/hellobaidumap]

The Baidu map SDK provides developers with an interface to conveniently display Baidu map data. You can use Baidu map data in your application in the following steps:

Step 1: Create and configure a project (For details, refer to the project configuration section );

Step 2: add the development key and required permissions to AndroidManifest;

(1) Add a development Key to the application

 
 
  
 

2) Add required permissions

 
   
    
     
      
       
        
         
          
          
         
        
       
      
     
    
   
  

Step 3: Add a map control to the layout xml file;

 
  

Step 4: Initialize the Context global variable referenced by the SDK when creating an application:

 
Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // 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 );}}

Note: You must call each function component of the SDK before using it.

SDKInitializer. initialize (getApplicationContext ();

Step 5: create a map Activity and manage the map lifecycle;

 
Public class MainActivity extends Activity {MapView mMapView = null; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // 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. bmapView) ;}@ Override protected void onDestroy () {super. onDestroy (); // execute mMapView when onDestroy is executed in activity. onDestroy () to implement mMapView for map lifecycle management. onDestroy () ;}@ Override protected void onResume () {super. onResume (); // execute mMapView when onResume is executed in the activity. onResume () to implement mMapView for map lifecycle management. onResume () ;}@ Override protected void onPause () {super. onPause (); // execute mMapView when onPause is executed in activity. onPause () enables mMapView for map lifecycle management. onPause ();}}

After completing the preceding steps, run the program to display the following map in your application:

5. FAQs

For the first configuration, you will certainly encounter many problems. Especially if most of the information on the Internet is about eclipse, you will encounter more problems when using Android studio.

Problem: The project code shows that the jar package cannot be found.

A: When copying the Baidu map jar package to libs under the project directory, you also need to add as library and create a folder under src/main/to store the. so file.

Problem: No implementation found for long com. baidu. platform. comjni. map. commonmemcache. JNICommonMemCache. Create

A: Create a folder under src/main/to store the. so file, and copy the v8a, v7a, and abi folders.

Problem: SHA1 acquisition

Answer: refer to the preceding section.

Problem:Failure [INSTALL_FAILED_NO_MATCHING_ABIS]

A: For a virtual device, select arm or package it directly to your mobile phone.

Problem: only the grid is displayed, and no map is displayed.

Answer: (1) No network; (2) any of the signature (SHA1), package name, and API key settings is incorrect; (3) the configuration in AndroidManifest is incorrect: for example, API permission, API_KEY, uses-permission, and meta-data location.

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.