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, but also in the near future positioning function, but found Baidu is really a big pit ah, the SDK named updated, the relevant code is not updated, I spent a very long time to study, today to share the next Android integrated Baidu Map to pay attention to things, here is only integrated positioning and map display function, 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 applications, and then you will see such as the following interface:

According to its requirements to fill in the relevant information, the security here is SHA1 and package name, the SHA1 and the package name after the completion of their own initiative, registration must know how to obtain, SHA1 way to obtain such as the following: (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 "Execute" input CMD Enter
CD C:\Program files\java\jdk1.7.0_71\bin (Install JDK path)
Keytool-list-v-keystore C:\users\your_user_name.android\debug.keystore-alias androiddebugkey-storepass Android- Keypass Android
For example: Keytool-list-v-keystore c:\users\Administrator.android\debug.keystore-alias androiddebugkey-storepass Android- Keypass Androidand and then I saw SHA1.
Assuming it is not, it can be obtained by means of a tool that detects if the key you generated is correct, click Get tool

The tool I found on the Internet, thank you here, downloaded 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, such as the following screen:

The SHA1 here is what you want, and it's also possible to add a key to your post to find out if it's correct.
After you click Submit, you will get the key you want in your app list. Next is to see how to integrate Baidu map into your project.
Go to homepage-The following Android development-any feature-download in the lower left corner-custom download will appear for example the following interface:

You want to integrate what features, you choose which feature to download the development package here, the development package has you want to integrate the relevant features of the jar package, I do not recommend downloading the demo sample code, as I mentioned in the beginning, Baidu Map SDK has been updated, but the demo sample code or the old version number, Let's say you take the Demo sample code, which will give you a very big misleading!!!!
Copy and paste the contents of the development package you just downloaded into your project libs, assuming you're using 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 to the 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. Users write 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 and you can
Next is in the demo in the positioning and map display, in my demo is very specific, the related gaze also has, can download under the view, here no longer repeat, to note that in the integration of the function of the map display, found that execution will 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.