Baidu map Development Learning (1): Baidu map Development Learning

Source: Internet
Author: User

Baidu map Development Learning (1): Baidu map Development Learning

Due to project requirements, I recently learned how to develop Android maps, So I recorded the learning process. It will be updated one after another recently. Currently, Baidu map APIs are widely used, so we need to learn some map calls based on them.

I. AK Application

Unlike web development, Android Map project development requires an AK to call the map function.

1. Register as a Baidu developer and enter the information normally.

2. Apply for a key:

Create an application at http://lbsyun.baidu.com/apiconsole/key. now, only one key can be applied to one application.

(1) Application name: Same as the name of the project you created.

(2) Application Type: Android SDK

(3) start the service: it is recommended to select all options to facilitate the subsequent addition of functions to the project.

(4) digital signature (SHA1 ):

Run the command line on Android studio and start it directly to enter the C: \ USERNAME \. android: Enter keytool-list-v-keystore debug. keystore (the keystore command is android), and the certificate fingerprint will appear. paste the SHA1 value in the past.

Because the SHA1 method recommended by Baidu may be incorrect, many people on the Baidu forum, including myself, may also encounter an incorrect SHA1 value, resulting in an AK pair failure, on the forum, we can see an official app for AK testing. It can obtain the correct SHA1 and package names for all applications. We can replace the previous errors. This is the URL: http://bbs.lbsyun.baidu.com/forum.php? Mod = viewthread & tid = 85103 & extra = page % 3D1

(5) package name: build. gradle in the app file in Android studio. applicationId indicates the package name.

 

2. Download the SDK

1. At URL: http://lbsyun.baidu.com/index.php? Title = androidsdk/sdkandev-download

One-click Download will include the jar package, so file, and some demos, which will be easier to view later.

2. The next step is to create a project in android studio. Do not talk about the process. After the project is created, add the jar package and so file.

Jar package: add the package to the libs file, right-click it, and select add as library;

So file: Create a jniLibs file under the main file and paste the so files in various compiling environments.

3. Declare the AK and permission in AndroidManifest. xml.

AK:

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

Permissions (relatively complete permissions ):

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_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.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

4. Add a map control to the layout file.

 

<Com. baidu. mapapi. map. MapView
Android: id = "@ + id/bmapView"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: clickable = "true">
</Com. baidu. mapapi. map. MapView>



5. When creating an application, you need to initialize the SDK and reference the global variable:

 


6. Create a basic map:

You can use the basic map by declaring the control reference in the main thread to display the basic map information.
MMapView = (MapView) findViewById (R. id. bmapView );
Manage the Declaration cycle and synchronize the MAP status at each stage.
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}

@Override
protected void onResume() {
super.onResume();
mMapView.onResume();
}

@Override
protected void onPause() {
super.onPause();
mMapView.onPause();
}

 

The location acquisition, map POI retrieval, and route planning will be updated later.

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.