Integration of Android development Baidu map positioning and map display

Source: Internet
Author: User
Tags sha1

App application, most of the applications have positioning function, Baidu positioning has become the developer's integrated positioning function of choice, recently also in the positioning function, but found Baidu is really a big pit ah, the SDK named updated, the relevant code is not updated, I took a long time to study, today to share the next Android integrated Baidu Map to pay attention to things, here is just integrated positioning and map display features, other features are not covered, first look at:

Next introduce the steps of Android integrated Baidu map:
First login to the Baidu development platform, in my application to create an application, and then you will see the following interface:

According to its requirements to fill in the relevant information, the security here is a SHA1 and package name, will be SHA1 and the package name after completion will be automatically generated, registration must know how to obtain, SHA1 to obtain the way as follows: (Android Studio)
Mac Version:
Open the Terminal in Android Studio and enter the command line
Keytool-list-v-keystore ~/.android/debug.keystore-alias androiddebugkey-storepass android-keypass Android
Press ENTER to be able to SHA1;
Window version:
Win+r Open "Run" input CMD enter
CD C:\Program files\java\jdk1.7.0_71\bin (JDK installation path)
Keytool-list-v-keystore C:\users\your_user_name.android\debug.keystore-alias androiddebugkey-storepass Android- Keypass Android
Example: Keytool-list-v-keystore c:\users\Administrator.android\debug.keystore-alias androiddebugkey-storepass Android- Keypass Androidand and then I saw SHA1.
If it doesn't work, it can be obtained through a tool that detects if the key you generated is correct, click Get tool

The tool I found on the Internet, thank you here, download completed and installed on the phone, click on the tool just installed, it will be used in the phone to retrieve the application, and then click on the app you want to get key, the following screen appears:

The SHA1 here is what you want, and you can also add the key after you have been added here to detect whether the correct
After you click Submit, you will get the key you want in your app list. Next, look at how to integrate Baidu maps into your project.
Go to Home-Android development below-any feature-download in the lower left corner-Custom download, the following interface appears:

You want to integrate what features, you choose which function, here to download the development package, the development package has you want to integrate the relevant features of the jar package, I do not recommend downloading the sample code, as I mentioned in the beginning, Baidu Map SDK has been updated, but the sample code is still old version, if you refer to the sample code, will bring you a lot of misleading!!!!
Copy and paste the contents of the development package you just downloaded into the Libs of your project, and if you use Android Studio, don't forget to add it under build

sourceSets {        main {            jniLibs.srcDirs = [‘libs‘]        }    }

Then just configure your manifest file:
First, permissions:

<!--This permission is used for network positioning --    <uses-permission android:name="Android.permission.ACCESS_COARSE_LOCATION"> </uses-permission>    <!--this permission to access GPS location --    <uses-permission android:name="Android.permission.ACCESS_FINE_LOCATION"> </uses-permission>    <!--used to access WiFi network information, WiFi information is used for network location--    <uses-permission android:name="Android.permission.ACCESS_WIFI_STATE"> </uses-permission>    <!--get carrier information to support interfaces that provide operator information--    <uses-permission android:name="Android.permission.ACCESS_NETWORK_STATE"> </uses-permission>    <!--this permission to get access to WiFi, WiFi information is used for network location --    <uses-permission android:name="Android.permission.CHANGE_WIFI_STATE"> </uses-permission>    <!--to read the current state of the phone--    <uses-permission android:name="Android.permission.READ_PHONE_STATE"></uses-permission>    <!--write extended storage, write data to the expansion card for writing offline location data- -    <uses-permission android:name="Android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>    <!--access network, network location needs internet--    <uses-permission android:name="Android.permission.INTERNET" />    <!--SD card read access, user writes offline location data--    <uses-permission android:name="Android.permission.MOUNT_UNMOUNT_FILESYSTEMS" ></uses-permission>

Then is the service of Baidu map:

<service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote"/>

The last and most important is the configuration-specific key,

<meta-data            android:name="com.baidu.lbsapi.API_KEY"            android:value=""//key:开发者申请的key

Add the key you just acquired on the Baidu platform to here
Next is in the demo in the positioning and map display, in my demo write very detailed, related comments also have, can download under the view, here no longer repeat, to note that in the integration of the function of the map display, found that the operation will be error, that is because there is no initialization:

SDKInitializer.initialize(getApplicationContext());

And the method is added to the front of the Setcontentview () method, so we choose to add the method to application.
QQ Technology Group: 190088567
Project:
http://download.csdn.net/detail/xiaoxin_android/9493348

Integration of Android development Baidu map positioning and map display

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.