Android Baidu Map Development-First: application, build Baidu Map

Source: Internet
Author: User
Tags sha1

First, preface

This is the first learning record on Android using Baidu maps, the main record:
1. Apply for API Key on the Baidu Map developer platform.
2. Add Baidu Map's Android SDK to your app.
3. Display a map in your app.

Second, apply for API Key on the Baidu map developer platform

Baidu Map Developer platform address: http://lbsyun.baidu.com/index.php?title=%E9%A6%96%E9%A1%B5. Click on "Request Key" in the interface and click on the "Create app" button after entering the interface.



Choose the app type as "Android SDK", fill in the app name, release version SHA1, develop version SHA1, so I suggest you create your app now and see what you need to fill out. Here my application name is "Baidu map test", the package is called "Com.zhangmiao.baidumaptest11_4".
How to view the published, developed version of SHA1:

1. Get the development version of SHA1:

Input command: keytool-list-v-keystore debug.keystore, enter
Enter KeyStore Password: Android (system default) carriage return.

This will see the development version of SHA1.

2. Get the release version of sha1:2.1. Create your own signature file

Select the Build->generate signed APK in the Android studio software. Click on the Next button

Here you can choose Create new Key store or choose Existing Key Store, select the existing KeyStore file is also possible, directly select, here, I introduce the steps to create a new KeyStore, click Create New Key Store button,

Key Store Path: Select the file path and name of the KeyStore.
Password: Password
Confirms: Enter the password again
Alias: Aliases
Password:key's password
Confirms: Enter the password again
Validity (years): Validity period of the key
First and last name: your name
Organizational unit: Unit
Organization: Organization
City or Locality: cities or locations
State or province: Province
Country Code (XX): Country
After completion, click "OK" button to return to the Generate signed APK interface, this time found the interface key store password, key alias, key password has been automatically filled out,
Click "Next" button, the Enter Master password interface appears (some may not appear this interface),

Fill in the password, click "OK" button,

The option for Build type is release, and also remember to tick the signature versions option. Click the Finish button to create the KeyStore file for the development version here.

2.2. View the release version of SHA1

Enter the command: Keytool-list-v-keystore "Create the address of the KeyStore file for the release", enter.
Enter KeyStore Password: What is set above, what to fill in here.

This will see the release version of SHA1.
The published version and the development version of SHA1 are filled into the corresponding input box. then click Submit.

Third, in their own application to add Baidu Map of the Android version of the SDK

First download Baidu maps Android version of the Sdk::http://lbsyun.baidu.com/index.php?title=androidsdk/sdkandev-download, click on Custom Download, tick the features you need, Click on the development package to download.
After the download is complete, unzip the package and put all the files inside the Libs into the Libs folder of your project. Add the following statement to the Build.gradle of the project:

Android {   ...    Sourcesets {        main {            jnilibs.srcdirs = [' Libs '}        }    }

This introduces the Baidu map API in your project.

Iv. displaying a map in your application 1. Modify the Activity_main layout
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <com. Baidu.mapapi.map.MapView Android:id= "@+id/map_view"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:clickable= "true" /></LinearLayout>
2. Add Api_key

In the Androidmanifest.xml file, add the Api_key for application

    < Application         ... >        <  android:name= "Com.baidu.lbsapi.API_KEY"            android:value= " View your app's (Access application) AK "/>" in the Baidu Map developer platform Interface
3. Modify the Mainactivity file
 Public classMainactivityextendsappcompatactivity {PrivateMapview Mmapview =NULL; PrivateBaidumap Bdmap; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Requestwindowfeature (Window.feature_no_title);        Sdkinitializer.initialize (Getapplicationcontext ());        Setcontentview (R.layout.activity_main); Mmapview=(Mapview) Findviewbyid (R.id.map_view); } @Overrideprotected voidOnresume () {Super. Onresume ();    Mmapview.onresume (); } @Overrideprotected voidOnPause () {Super. OnPause ();    Mmapview.onpause (); } @Overrideprotected voidOnDestroy () {Super. OnDestroy ();        Mmapview.ondestroy (); Mapview.setmapcustomenable (false); Mmapview=NULL; }}
4. Add Permissions

Add the following permissions in Androidmanifest.xml:

    <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE" />    <uses-permissionAndroid:name= "Android.permission.INTERNET" />    <uses-permissionAndroid:name= "Android.permission.ACCESS_WIFI_STATE" />    <uses-permissionAndroid:name= "Android.permission.CHANGE_WIFI_STATE" />    <uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE" />    <uses-permissionAndroid:name= "Android.permission.WRITE_SETTINGS" />    <uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE" />    <uses-permissionAndroid:name= "Android.permission.CALL_PHONE" />    <uses-permissionAndroid:name= "Android.permission.ACCESS_FINE_LOCATION" />    <uses-permissionAndroid:name= "Android.permission.ACCESS_COARSE_LOCATION" />

Now you can run the program, you can see the map appears.

Code Address: Https://github.com/ZhangMiao147/BookCode_TheFirstLineOfCode/tree/master/baidumaptest11_4

Android Baidu Map Development-First: application, build Baidu Map

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.