The simplest example of introducing Baidu map to android-HelloBaiDuMap

Source: Internet
Author: User

The simplest example of introducing Baidu map to android-HelloBaiDuMap
The Baidu Map Display SDK provides developers with an interface to conveniently display Baidu map data. You can use Baidu map data in your application in the following steps: Step 1: create and configure a project (For details, refer to the project configuration section). Step 2: add development keys, required permissions, and other information to AndroidManifest. (1) add the development Key <application <meta-data android: name = "com. baidu. lbsapi. API_KEY "android: value =" Developer key "/> </application> (2) Add the required permission <uses-permission android: name =" android. permission. GET_ACCOUNTS "/> <uses-permission android: name =" android. permission. USE_CREDENTIALS" /> <Uses-permission android: name = "android. permission. MANAGE_ACCOUNTS "/> <uses-permission android: name =" android. permission. AUTHENTICATE_ACCOUNTS "/> <uses-permission android: name =" android. permission. ACCESS_NETWORK_STATE "/> <uses-permission android: name =" android. permission. INTERNET "/> <uses-permission android: name =" com. android. launcher. permission. READ_SETTINGS "/> <uses-permission android: name =" Droid. permission. CHANGE_WIFI_STATE "/> <uses-permission android: name =" android. permission. ACCESS_WIFI_STATE "/> <uses-permission android: name =" android. permission. READ_PHONE_STATE "/> <uses-permission android: name =" android. permission. WRITE_EXTERNAL_STORAGE "/> <uses-permission android: name =" android. permission. BROADCAST_STICKY "/> <uses-permission android: name =" android. permission. WRITE_SETTINGS "/> <Uses-permission android: name = "android. permission. step 3: Add a map control to the layout xml file. <com. baidu. mapapi. map. mapView android: id = "@ + id/bmapView" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: clickable = "true"/> Step 4, load configuration item: package com. example. mybaidumap; import com. baidu. mapapi. BMapManager; import com. baidu. mapapi. MKGeneralListener; import com. baidu. mapapi. map. mapC Ontroller; import com. baidu. mapapi. map. mapView; import com. baidu. platform. comapi. basestruct. geoPoint; import android. OS. bundle; import android. app. activity; import android. view. menu; public class MainActivity extends Activity implements MKGeneralListener {private BMapManager mBMapMan = null; private MapView mMapView = null; private MapController mMapController = null; protected void onCreate (Bundl E savedInstanceState) {super. onCreate (savedInstanceState); mBMapMan = new BMapManager (getApplication (); mBMapMan. init (this); setContentView (R. layout. activity_main); // obtain the map control reference mMapView = (MapView) findViewById (R. id. bmapView); mMapView. setBuiltInZoomControls (true); // set scaling} @ Override protected void onDestroy () {super. onDestroy (); // execute mMapView when onDestroy is executed in activity. onDestroy () for mMapView of map lifecycle management. Destroy () ;}@ Override protected void onResume () {super. onResume (); // execute mMapView when onResume is executed in the activity. onResume () to implement mMapView for map lifecycle management. onResume () ;}@ Override protected void onPause () {super. onPause (); // execute mMapView when onPause is executed in activity. onPause () enables mMapView for map lifecycle management. onPause () ;}@ Override public void onGetNetworkState (int arg0) {// TODO Auto-generated method stub} @ Override public void onGetP ErmissionState (int arg0) {// TODO Auto-generated method stub} Last step: Run your app to view Baidu map.

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.