Android introduced Baidu map the most simple example-hellobaidumap

Source: Internet
Author: User

Development Tools

I am using eclipse, which is currently the most developed tool for Android.

Development Preparation

First need in the Baidu Map development platform to download the required documents and functions, due to the latest version of the 3.0.0 is not very familiar with, I use a slightly older version: 2.4.1 version; here is: http://developer.baidu.com/map/ Sdkandev-download.htm. I am in the lower right corner of this page by clicking on the version of the history download 2.4. Version 1:

After the download, it has such a compressed file:

After unpacking, this is the three compressed package:

Where sample is its demo, after unpacking it is this:

After opening the inside is a variety of functions of the demo;

project Configuration

The first step: the entire copy of the Lib folder in the development package, and then paste it into your project folder, overwriting the original file, then the following:

The second step: select "Add External JARs" in the project properties->java Build path->libraries, choose Baidumapapi_v2_4_1.jar, and return when determined.

With the above two steps, you will be able to use the Baidu Map SDK to provide you with all the functions.

Note: Because of the ADT plugin upgrade, if you are using Eclipse ADT 22, you need to set the development environment accordingly, as follows:

1. Select project in Eclipse, right-click Properties->java Build path->order and Export to make Android Private libraries tick;

2. Project-clean-> clean all.

Show Baidu Map

Baidu Map SDK for developers to provide a convenient display of Baidu map data interface, through the following steps, you can use the Baidu map data in your application:

The first step: Create and configure the project (see the Project configuration section for details);

The second step: Add the development key, the required permission and other information in the androidmanifest;

(1) Add a development key in application

<application      <meta-data          android:name="Com.baidu.lbsapi.API_KEY" Android : Value=
</application>

(2) Add the required permissions

<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="Android.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< Span class= "sy0" >-permission android:name= "Android.permission.WRITE_SETTINGS" />
<uses< Span class= "sy0" >-permission android:name= "Android.permission.READ_PHONE_STATE" />

The third step is to 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=/>    

Fourth step, load the configuration item:

Package com.example.mybaidumap;

Import Com.baidu.mapapi.BMapManager;

Import Com.baidu.mapapi.MKGeneralListener;

Import Com.baidu.mapapi.map.MapController;

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 (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Mbmapman = new Bmapmanager (Getapplication ());

Mbmapman.init (this);

Setcontentview (R.layout.activity_main);

Get map Control Reference

Mmapview = (Mapview) Findviewbyid (R.id.bmapview);

Mmapview.setbuiltinzoomcontrols (TRUE);//Set Scaling

}

?

@Override

protected void OnDestroy () {

Super.ondestroy ();

Implement Mmapview.ondestroy () when activity executes OnDestroy to achieve map life cycle management

Mmapview.destroy ();

}

@Override

protected void Onresume () {

Super.onresume ();

Executes Mmapview when the activity executes Onresume. Onresume () for map life cycle management

Mmapview.onresume ();

}

@Override

protected void OnPause () {

Super.onpause ();

Executes Mmapview when the activity executes OnPause. OnPause () for map life cycle management

Mmapview.onpause ();

}

@Override

public void ongetnetworkstate (int arg0) {

TODO auto-generated Method Stub

}

@Override

public void ongetpermissionstate (int arg0) {

TODO auto-generated Method Stub

}

}

The last step: Run your app to see Baidu map.





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.