recently made Android Baidu map, but use Baidumapapi_v2_3_1.jar and libbaidumapsdk_v2_3_1.so display Baidu map always encountered problems-only display grid and not show the map, Network connection and Apikey application are correct, just do not know why not show, there are many people on the Internet encountered this problem, there are some SDK updates are incompatible. And many Baidu maps on the Internet are using the V2.3.1 version, and then there is no way only through Baidumapapi_v2_4_1. The jar finishes displaying the map.
It is important to note that when using 2.3.1, Manager.init ("APIKey", null) is initialized, and the 2.4.1 version is entered in Androidmanifest.xml by the AK.
PS: This is only a basic article on the development of the Baidu map of Android, online information is also many, but the method is feasible. Refer to Guo Shen "Android first line code" in the method also v2.3.1 can only display the grid and no map.
I. Application for apikey before development
Resources:
Official Development SDK Guide http://developer.baidu.com/map/sdkandev-14.htm
Baidu Map Application key Http://lbsyun.baidu.com/apiconsole/key
First, register as a Baidu developer.
Submit the registration successfully as shown below.
Click "Go to create app >>", as shown here, showing your app list.
Click "Create App" to request Apikey, select the type of blog books we have seen before usually choose the "for mobile" app type, there is no such option, so choose "for Android", and enter the security code!
Here you may wonder what "Security Code" is? It consists of "digital signature; package name", where the digital signature is the SHA1 fingerprint of KeyStore when we packaged the program, by clicking Eclipse's Form (window), Preferences (Preferences), Android->build "View, also can refer to the above Official document link through cmd get." The package name is the package name of the application. 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 directory in the created Application Baidumapshow project, while creating a new Armeabi directory under Libs directory, and copy Libbaidumapsdk_v2_4_1. So file. As shown in:
where the project package named Com.eample.baidumapshow,libs directory is used for storing third-party jar packages, the Armeabi directory holds the NDK generated so file to call its C + + function library. Also need to import jar package, right-click Project--" Properties (attributes), Java build path, as shown in Add jar.
three. Source code display Baidu map
1.activity_main.xml Layout File
The layout file is loaded by the Baidu map control Mapview, which is provided by Baidu's custom control so it needs to add the full package name, and 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 detailed 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 () {/** * map will be returned when the move is complete Adjust this interface method */@Override public void Onmapmovefinish () {Toast.maketext (Mai Nactivity.this, "Map movement", Toast.length_short). Show (); }/** * Map loading complete 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 completes the draw-driven operation (e.g., Animationto ()) */@Overri De public void onmapanimationfinish () { /** * When Mmapview.getcurrentmap () is called, this callback is triggered * can be saved here to storage device */@Override public void Ongetcurrentmap (Bitmap arg0) { /** * Click on the marked point on the map to callback this method * */@Ove Rride 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
One of 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 "> <USES-SD K android:minsdkversion= "android:targetsdkversion="/> <!--Get network status--<uses-permi Ssion android:name= "Android.permission.ACCESS_NETWORK_STATE"/> <!--access 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 "/> <!--allow program to write 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. Run the effect as shown
finally hope that the article to help, 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 labels and other functions bar! I don't know why I always show the grid without a map for the previous question. However, the map can be displayed by V2_4_1.
I guess the reason is that the previous application of the Apikey call method can be implemented to display the map, but because of the new update of Baidu SDK method is not compatible, now apply for the apikey need to use the new method, so the above can display, personal opinion, do not know whether it is correct AH!
(By:eastmount 2014-12-22 night 2 o ' http://blog.csdn.net/eastmount/)
Resources:
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