[Android] Baidu Map Development (a). Apply for AK display map and solve the problem of displaying blank grid

Source: Internet
Author: User

recently do Android Baidu map, but use Baidumapapi_v2_3_1.jar and libbaidumapsdk_v2_3_1.so display Baidu map always encountered problems-just display grid and not show map , network connection and Apikey application are correct, just do not know why not show, there are a lot of people on the Internet have encountered this problem, there are some SDK updates are incompatible. And online very much Baidu map is the use of V2.3.1 version number, and then there is no way only through BAIDUMAPAPI_V2 _4_1.jar finished showing the map.
It is important to note that when using 2.3.1, the Manager.init ("APIKey", null) is initialized, and the 2.4.1 version number is entered by the AK in Androidmanifest.xml Meta-data.
PS: This is an Android development Baidu map of the basic article, the online data is also very much, but the method is feasible. The method in the Guo Shen "Android first line code" is also v2.3.1 can only display the grid and no map.

I. Application for apikey before development

References:
Official Development SDK Guide http://developer.baidu.com/map/sdkandev-14.htm
Baidu Map Application key Http://lbsyun.baidu.com/apiconsole/key
First of all, register to become a Baidu developer.

After submitting the registration successfully for example, see.

Click "Go to create app >>", for example, to see a list of your apps displayed here.

Click "Create App" to apply Apikey, select type once we have seen the blog book is generally selected "for mobile" application type, there is no such option, so I choose "for Android", the same time enter the security code!

Here you may wonder what "Security Code" is?

It is composed of "digital signature; package name", in which the digital signature is the SHA1 fingerprint of KeyStore when we packaged the program, by clicking on Eclipse's Window (Windows), Preferences (Preferences)->android-> Build "View, at the same time can also participate in the above official document link through CMD get. The package name is the package name of the application. For example, the following:
E5:ba:71:31:9d:a3:bf:92:8d:2e:8f:3a:6d:0a:93:5b:3d:36:59:08;com.example.baidumapshow

Click "Submit" to get the AK: QWANHFQ0TY2QMDYH3NRR0GQX


two. Configuring the project Call SDK

download Android SDK address:
http://developer.baidu.com/map/sdkandev-download.htm
Copy the Baidumapapi_v2_4_1.jar file under the Libs folder in the created Application Baidumapshow project, create a new Armeabi folder under Libs folder at the same time, and copy the Libbaidumapsdk_v2_4 _1.so files. For example , as seen in:

the project package named Com.eample.baidumapshow,libs folder is used for storing third-party jar packages, and the Armeabi folder holds the NDK generated so file to call its C + + function library. You need to import the jar package at the same time, Right-project-> "Properties", "Java Build path", for example, adding a jar as seen.


three. Source Display Baidu Map

1.activity_main.xml Layout File
Layout file by loading Baidu map control Mapview, it is provided by Baidu's own definition of the control needs to add the full package name, the same time the control needs to accept the Click event clickable set to True.

<framelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:id=" @+id/container "    android:layout_width=" Match_parent "    Android : layout_height= "match_parent"    tools:context= "com.example.baidumapshow.MainActivity"    tools:ignore= " Mergerootframe ">    <com.baidu.mapapi.map.mapview        android:id=" @+id/map_view "        android:layout_ Width= "Match_parent"        android:layout_height= "match_parent"        android:clickable= "true"/></ Framelayout>
2.mainactivity.java file
public class Mainactivity extends Activity {//bmapmanager Object management map, location, search function private Bmapmanager mbmapmanager;  Mapview Map main control private Mapview mapview = null;   Mapcontroller Complete Map Control private Mapcontroller mmapcontroller = null;    Mkmapviewlistener for handling map event callbacks Mkmapviewlistener Mmaplistener = null;                @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); /** * Create object Bmapmanager and initialize operation * V2.3.1 init (apikey,null) V2.4.1 in Androidmanifest assign AK * Note initialization operation in S          Etcontentview () front */Mbmapmanager = new Bmapmanager (Getapplication ());         Mbmapmanager.init (NULL);                  Setcontentview (R.layout.activity_main);          Mapview = (Mapview) Findviewbyid (R.id.map_view);          Get the map controller get Mapcontroller Instance Mmapcontroller = Mapview.getcontroller ();          Sets whether the map responds to click event Mmapcontroller.enableclick (TRUE);   Set map zoom level 3-19 level higher information more specific mmapcontroller.setzoom (16);       Displays the built-in zoom control Mapview.setbuiltinzoomcontrols (TRUE); /** * Get school latitude and longitude set Map center point */GeoPoint points = new GeoPoint ((int) (39.96703 * 1E6), (int) (116.323772 * 1E)          6));          Mmapcontroller.setcenter (point); Mapview.regmapviewlistener (Mbmapmanager, New Mkmapviewlistener () {/** * The map will be moved back when it is finished Adjust this interface method */@Override public void Onmapmovefinish () {Toast.maketext (Mai            Nactivity.this, "Map movement", Toast.length_short). Show (); }/** * Map loading completed callback This interface method */@Override Public V            OID Onmaploadfinish () {Toast.maketext (mainactivity.this, "map loading", Toast.length_short). Show (); /** * This callback is triggered when the map is finished (e.g., Animationto ()), */@Overri                   De public void onmapanimationfinish () {             }/** * When Mmapview.getcurrentmap () is called. This callback will be triggered * can be saved to storage device */@Override public void Ongetcurrentmap (Bitmap               arg0) {}/** * Click on the marked point on the map to callback this method * */@Override public void Onclickmappoi (Mappoi arg0) {if (arg0! = null                ) {Toast.maketext (Mainactivity.this, Arg0.strtext, Toast.length_short). Show ();      }              }          }); } @Overrideprotected void Onresume () {mapview.onresume (); if (Mbmapmanager! = null) {Mbmapmanager.start ();}        Super.onresume ();} @Overrideprotected void OnDestroy () {Mapview.destroy (); if (Mbmapmanager! = null) {Mbmapmanager.destroy (); Mbmapmanager = null;} Super.ondestroy ();} @Overrideprotected void OnPause () {mapview.onpause (); if (Mbmapmanager! = null) {mbmapmanager.stop ();} Super.OnPause ();}} 
3.androidmanifest.xml in the Declaration of Rights and Apikey
the most important is to add Apikey, method Mbmapmanager.init (NULL) call.
<meta-data
Android:name= "Com.baidu.lbsapi.API_KEY"
android:value= "QWANHFQ0TY2QMDYH3NRR0GQX" >
</meta-data>
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.example.baidumapshow "android:versioncode=" 1 "android:versionname=" 1.0 "> &LT;USES-SD K android:minsdkversion= "android:targetsdkversion="/> <!--Get network status--<uses-permi Ssion android:name= "Android.permission.ACCESS_NETWORK_STATE"/> <!--interview network--<uses-permission android:n Ame= "Android.permission.INTERNET"/> <!--get WiFi status-<uses-permission android:name= "android.permission . Access_wifi_state "/> <uses-permission android:name=" Android.permission.CHANGE_WIFI_STATE "/> <!--consent program written into external storage, such as SD card write file--<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-p Ermission android:name= "Android.permission.WRITE_SETTINGS"/> <!--read phone status--<uses-permission android:n Ame= "Android.permission.READ_PHONE_STATE "/> <uses-permission android:name=" Android.permission.CALL_PHONE "/> <!--get accurate position GPS chip receiving satellite positioning information, positioning accuracy up to 1 0 meters and <uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION"/> <!--via WiFi or mobile base station Take the user to the wrong latitude and longitude information--<uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION"/> <!--get analog positioning Info--<uses-permission android:name= "Android.permission.ACCESS_MOCK_LOCATION"/> <uses-permission Andro Id:name= "Android.permission.ACCESS_GPS"/> <application android:allowbackup= "true" Android:icon = "@drawable/ic_launcher" android:label= "@string/app_name" android:theme= "@style/apptheme" > <me Ta-data android:name= "Com.baidu.lbsapi.API_KEY" android:value= "QWANHFQ0TY2QMDYH3NRR0GQX" > </meta-d ata> <activity android:name= "com.example.baidumapshow.MainActivity" android:label= "@st     Ring/app_name ">       <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <    Category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application></manifest>
4. Performance effects such as those seen in the

finally hope that the article to help you, this is my classmates to do a simple study of Baidu Map of a basic article, which is ready to talk about the Baidu map POI interest Search and add features such as labeling! I don't know why I always show grids without a map for the previous question. But the map can be displayed by V2_4_1.
I have to test the reason is that the Apikey call method has been applied to achieve the display map, but because Baidu new updated SDK method is not compatible, now apply for the apikey need to use the new method, so the above talent display, personal opinion, do not know whether it is correct AH!
(By:eastmount 2014-12-22 night 2 o ' http://blog.csdn.net/eastmount/)

References:
1. Guo Lin "Android first line Code" 11th chapter based on the development of Baidu Map
2.xiaanming Great God article http://blog.csdn.net/xiaanming/article/details/11171581
3. Baidu Official documents and library http://wenku.baidu.com/view/86bab0b3f524ccbff12184bd.html

[Android] Baidu Map Development (a). Apply for AK display map and solve the problem of displaying blank grid

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.