The development of Baidu map in Rabbit--android

Source: Internet
Author: User

Effect:



API key Application Address: Http://lbsyun.baidu.com/apiconsole/key


Application notes:



Security Code: SHA1 Fingerprint value +;+ package name for the following interface

For example: 72dem98dme;com.map



、、、、、、、、、、、 folder Structure 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、


Code:

Mainactivity.java

Package Com.mybdmap;import Android.app.activity;import Android.graphics.bitmap;import android.os.Bundle;import Android.widget.toast;import Com.baidu.mapapi.bmapmanager;import Com.baidu.mapapi.mkgenerallistener;import Com.baidu.mapapi.map.mkevent;import Com.baidu.mapapi.map.mkmapviewlistener;import Com.baidu.mapapi.map.mapcontroller;import Com.baidu.mapapi.map.mappoi;import Com.baidu.mapapi.map.MapView;import Com.baidu.platform.comapi.basestruct.geopoint;public class Mainactivity extends Activity {private Toast mtoast; Private Bmapmanager mbmapmanager;private Mapview Mmapview = null;//with Mapcontroller complete map control private Mapcontroller Mmapcontroller = null;//mkmapviewlistener for handling map event callbacks Mkmapviewlistener Mmaplistener = null; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);//You need to initialize Bmapmanager before using the Map SDK, This must be initialized at Setcontentview () First mbmapmanager = new Bmapmanager (Getapplicationcontext ());//The first parameter is API key,//the second parameter is the frequent use of event snooping. Used to handle common network errors, authorization validation errors, and so on. You can also not join this callback interface MBMApmanager.init ("Replace with your own AK", New Mkgenerallistener () {//] authorization error when calling the callback function @overridepublic void ongetpermissionstate (int Ierror) {if (Ierror = = mkevent.error_permission_denied) {showtoast ("API key error, please check! ");}} Some network status error handling callback function @overridepublic void ongetnetworkstate (int ierror) {if (Ierror = = Mkevent.error_network_connect) { Toast.maketext (Getapplication (), "Your network is wrong!" ", Toast.length_long). Show ();}}); Setcontentview (r.layout.activity_main); Mmapview = (Mapview) Findviewbyid (r.id.bmapview); MMapController = Mmapview.getcontroller ();//sets whether the map responds to click events. Mmapcontroller.enableclick (TRUE);//set map zoom level Mmapcontroller.setzoom (12) ;//display built-in zoom control Mmapview.setbuiltinzoomcontrols (TRUE);//The class that holds the precision and latitude, GeoPoint p = new GeoPoint ((int) (22.547923 * 1E6), (int) ( 114.067368 * 1E6));//set P place as center point Mmapcontroller.setcenter (p); Mmapview.regmapviewlistener (Mbmapmanager, new Mkmapviewlistener () {////The map will callback this interface method @overridepublic void Onmapmovefinish () {//Showtoast ("The map has moved!

");} The map loading is complete callback This interface method @overridepublic void Onmaploadfinish () {showtoast ("Map loaded! ");} /** * This callback is triggered when the map is finished (e.g., Animationto ()), */@Overridepublic void Onmapanimationfinish () {}/** * when called Mmapview.getcurrentmap (), this callback is triggered to be saved to the storage device */@Overridepublic void Ongetcurrentmap (Bitmap arg0) {}/** * Click on the marked point on the map to callback this method * */@Overridepublic void Onclickmappoi (Mappoi arg0) {if (arg0! = null) {showtoast (Arg0.strtext);}});} The life cycle of the @Overrideprotected void Onresume () {//Mapview is synchronized with the activity. When activity hangs, call Mapview.onpause () Mmapview.onresume (); Super.onresume ();} The life cycle of the @Overrideprotected void OnPause () {//Mapview is synchronized with the activity. When activity hangs, call Mapview.onpause () Mmapview.onpause (); Super.onpause ();} The life cycle of the @Overrideprotected void OnDestroy () {//Mapview is synchronized with the activity. When the activity is destroyed, call Mapview.destroy () Mmapview.destroy ();//exit the application call Bmapmanager's Destroy () method if (Mbmapmanager! = null) { Mbmapmanager.destroy (); mbmapmanager = null;} Super.ondestroy ();} /** * Show Toast message * * @param msg */private void Showtoast (String msg) {if (mtoast = = null) {mToast = Toast.maketext (This, MSG, toast.length_short);} else {mtoast.settext (msg); Mtoast.setduration (Toast.length_short);} Mtoast.show ();}}


Layout file:

<?xml version= "1.0" encoding= "Utf-8"?

><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Fill_ Parent " android:layout_height=" fill_parent " android:orientation=" vertical "> < Com.baidu.mapapi.map.MapView android:id= "@+id/bmapview" android:layout_width= "Fill_parent" Android : layout_height= "fill_parent" android:clickable= "true"/></linearlayout>


Permissions:

  <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>    <uses-permission android: Name= "Android.permission.ACCESS_FINE_LOCATION"/>    <uses-permission android:name= " Android.permission.INTERNET "/>    <uses-permission android:name=" android.permission.WRITE_EXTERNAL_ STORAGE "/>    <uses-permission android:name=" Android.permission.ACCESS_WIFI_STATE "/>    < Uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE"/>    <uses-permission android:name= " Android.permission.READ_PHONE_STATE "/>    <uses-permission android:name=" android.permission.WRITE_ SETTINGS "/>


The required jar+so:http://download.csdn.net/detail/u013425527/8265569



The development of Baidu map in Rabbit--android

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.