Android calls Baidu map API and androidapi

Source: Internet
Author: User

Android calls Baidu map API and androidapi

1. Download the SDK from Baidu map development platform

Http://lbsyun.baidu.com/index.php? Title = androidsdk/sdkandev-download

1. Click custom download.

2. I have selected three feature packages for downloading them.

3. Obtain the key

Before getting the key, we need to create a new application.

 

Complete related information

2. Create a project

1. Copy the downloaded jar package from Baidu sdk to the libs directory of the project.

 

2. Add a development Key to the application

3. Add required permissions

<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="android.permission.WAKE_LOCK"/><uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.GET_TASKS" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.WRITE_SETTINGS" />

4. Add a map control and a button control to the layout xml file;

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.example.baidumap.MainActivity" >        <com.baidu.mapapi.map.MapView          android:id="@+id/bmapView"          android:layout_width="match_parent"          android:layout_height="match_parent"          android:clickable="true" /></LinearLayout>

5. Compile the src File

Public class MainActivity extends Activity {private MapView mMapView = null; private BaiduMap mBaiduMap; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // initialize the context information before using the SDK components, and pass in the ApplicationContext // note that this method must be implemented before the setContentView method. initialize (getApplicationContext (); setContentView (R. layout. activity_main); // initialize the control initView ();} private void initView () {// obtain the map control reference mMapView = (MapView) findViewById (R. id. bmapView); // obtain Baidu map mBaiduMap = mMapView. getMap (); // common map mBaiduMap. setMapType (BaiduMap. MAP_TYPE_NORMAL); // enable the traffic map mBaiduMap. setTrafficEnabled (true); // satellite map // mBaiduMap. setMapType (BaiduMap. MAP_TYPE_SATELLITE) ;}@ Override protected void onDestroy () {super. onDestroy (); // execute mMapView when onDestroy is executed in activity. onDestroy () to implement mMapView for map lifecycle management. onDestroy () ;}@ 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 ();}}

Iii. Run the project

Export the APK with the signature file. The SHA1 code of the signature file must be consistent with the SHA1 code entered when the Baidu map application is created.

 

 

 

For more functions, see the official Baidu map documentation.

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.