Android SDK Baidu Map via POI in-City retrieval introduction interface Use _android

Source: Internet
Author: User
Tags gettext stub

Baidu Map SDK not only for the vast number of developers to provide a cool map display effect, rich overlay layer, more developers to provide a variety of LBS search capabilities. Through these interfaces, developers can easily access Baidu's LBS data, enrich their mobile-end map applications.

The current Baidu map SDK for developers to provide the search services are:

POI Search: Can search Baidu POI data information;

Line planning: Use Baidu's engine to help developers plan their routes;

Online recommended search, short link sharing, geo-coding, etc. ....

This article will be a very simple POI in the city for example, like the vast number of developers to introduce the use of interfaces.

The first step is to select and download the SDK;

This example we only use the search function, so we go to Baidu LBS open platform of Android's unified resource download platform to download the search function module can be, the specific address is as follows: Http://lbsyun.baidu.com/sdk/download

The second step is to create the Android project, and download a good SDK into the project;

After the import is complete, the effect is shown in the following illustration:

The third step is to design the interactive interface of the application;

The fourth step is to add the required permissions and Key required for SDK development in Androidmanifest;

<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-permission Android:name= "Android.permission. 
Write_settings "/> <uses-permission android:name=" Android.permission.READ_PHONE_STATE "/> <meta-data  Android:name= "Com.baidu.lbsapi.API_KEY" android:value= "Gbm9sbm00c7cd6vfi2evzsgk"/>

Note that the above key to the developer to change their application key, specific methods please refer to the previous blog introduction.

The fifth step, programming;

Define three variables separately, Poisearch, Poicitysearchoption, Ongetpoisearchresultlistener. As you can see from these three names, these three variables are the listening methods for retrieving objects, retrieving parameters, and retrieving results.

Before performing POI retrieval, you need to initialize the Poisearch object as follows:

Poisearch = Poisearch.newinstance ();

After initialization is complete, you need to set up its listening method, note that all the retrieval requests in the SDK are implemented asynchronously, and the code is as follows:

Poisearch.setongetpoisearchresultlistener (Ongetpoisearchresultlistener);

When the preparation is complete, we add the real search execution code in the button's click Response, as follows:

Button.setonclicklistener (New View.onclicklistener () { 
@Override public 
void OnClick (View arg0) { 
//TODO auto-generated method Stub 
poicitysearchoption = new Poicitysearchoption () 
. City (City.gettext (). toString ()) 
. Keyword (keyword.gettext (). toString ()); 
Poisearch.searchincity (poicitysearchoption); 
} 
);

Add the implementation of the Listener method, as follows:

Ongetpoisearchresultlistener Ongetpoisearchresultlistener = new Ongetpoisearchresultlistener () { 
@Override 
public void Ongetpoiresult (Poiresult poiresult) { 
//TODO auto-generated method stub 
String poiname = poiresult.g Etallpoi (). Get (0). Name; 
String Poiadd = Poiresult.getallpoi (). Get (0). Address; 
String idstring = Poiresult.getallpoi (). Get (0). uid; 
Textview.settext ( 
"First result is: \ n name =[" + 
poiname+ 
"]\nid = [" + 
idstring 
+ "] \ n Address =[" + 
Poiadd + 
"]"); 
} 
@Override public 
void Ongetpoidetailresult (Poidetailresult arg0) { 
//TODO auto-generated method stub 
} 

such as the listening method is to the results of the first information is displayed, the implementation of the program as follows diagram effect:

The above is a small set to introduce the Android SDK Baidu map through the POI in the city to retrieve the use of the interface, I hope to help.

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.