Rabbit-Development of Baidu map in android, rabbit-android

Source: Internet
Author: User

Rabbit-Development of Baidu map in android, rabbit-android

Effect:



Application address of API Key: http://lbsyun.baidu.com/apiconsole/key


Application notes:



Security code: The SHA1 fingerprint value of the following interface +; + package name

Example: 72dem98dimethyl; com. map



, Directory 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. mapV Iew; import com. baidu. platform. comapi. basestruct. geoPoint; public class MainActivity extends Activity {private Toast mToast; private BMapManager mBMapManager; private MapView mMapView = null; // map control using MapController private MapController mMapController = null; // MKMapViewListener is used to process map Event Callback MKMapViewListener mMapListener = null; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (s AvedInstanceState); // BMapManager needs to be initialized before using the map sdk. This must be initialized before setContentView () mBMapManager = new BMapManager (getApplicationContext ()); // The first parameter is the API key, and the second parameter is a common event listener, which is used to handle common network errors and authorization verification errors, you can also choose not to add this callback interface mBMapManager. init ("Replace with your own AK", new MKGeneralListener () {// callback function called when an authorization error occurs @ Overridepublic void onGetPermissionState (int iError) {if (iError = MKEvent. ERROR_PERMISSION_DENIED) {showToast ("api key error, please check! ") ;}} // Some network status error handling callback functions @ Overridepublic void onGetNetworkState (int iError) {if (iError = MKEvent. ERROR_NETWORK_CONNECT) {Toast. makeText (getApplication (), "your network has an error! ", Toast. LENGTH_LONG ). show () ;}}); setContentView (R. layout. activity_main); mMapView = (MapView) findViewById (R. id. bmapView); mMapController = mMapView. getController (); // sets whether the map responds to the click event. mMapController. enableClick (true); // sets the map zoom level mMapController. setZoom (12); // display the built-in zoom control mMapView. setBuiltInZoomControls (true); // class that stores the precision and latitude, GeoPoint p = new GeoPoint (int) (22.547923*1E6), (int) (114.067368*1E6 )); // Set p as the center point MMapController. setCenter (p); mMapView. regMapViewListener (mBMapManager, new MKMapViewListener () {// This interface method will be called back when map movement is complete @ Overridepublic void onMapMoveFinish () {// showToast ("the map has been moved! ");} // Call back after the map is loaded. @ Overridepublic void onMapLoadFinish () {showToast (" the map has been loaded! ");}/*** After the map completes the animation-carrying operation (for example, animationTo (), this callback is triggered */@ Overridepublic void onMapAnimationFinish () {}/*** when mMapView is called. after getCurrentMap (), this callback will be triggered and can be saved to the storage device */@ Overridepublic void onGetCurrentMap (Bitmap arg0) {}/*** click the marked point to callback this method **/@ Overridepublic void onClickMapPoi (MapPoi arg0) {if (arg0! = Null) {showToast (arg0.strText) ;}}) ;}@ Overrideprotected void onResume () {// synchronize the life cycle of MapView with Activity. When the activity is suspended, MapView must be called. onPause () mMapView. onResume (); super. onResume () ;}@ Overrideprotected void onPause () {// synchronize the life cycle of MapView with the Activity. MapView must be called when the activity is suspended. onPause () mMapView. onPause (); super. onPause () ;}@ Overrideprotected void onDestroy () {// The Life Cycle of MapView is synchronized with the Activity. When the activity is destroyed, MapView must be called. destroy () mMa PView. destroy (); // exit the application and call the destroy () method of BMapManager if (mBMapManager! = Null) {mBMapManager. destroy (); mBMapManager = null;} super. onDestroy ();}/*** display the 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>

Permission:

  <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" />


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



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.