"Public transportation information Retrieval" of Baidu Map development

Source: Internet
Author: User

The last time we studied the most basic POI search, today we look at, personally feel more useful bus line retrieval.

Let's look at the methods in this class

Package Com.baidu.mapapi.search.busline

Buslineresult Public transport Information Query results
Buslineresult.busstation Bus site Information
Buslineresult.busstep Bus route segment Information
Buslinesearch City bus information (including metro information) query This interface is used to query the entire bus line information Bus transfer route query please seeRoutePlanSearch
Buslinesearchoption City Bus Information Query parameters

>>uslinesearch

void destroy()Releasing a Retrieved object resource
static buslinesearch newinstance () get a new retrieval instance
boolean searchbusline (buslinesearchoption  Option) Bus retrieval portal
void setOnGetBusLineSearchResultListener(OnGetBusLineSearchResultListener listener)Set public transport details search results Monitor listener
>>buslinesearchoptionThe parameters are as follows

buslinesearchoption City (java.lang.string city) Set Query City
BusLineSearchOption uid(java.lang.String uid)Set the bus route UID.

Combine POI search to complete today's example

The XML file still contains only a ListView

<relativelayout 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 "    tools:context= ". Indexactivity ">    <listview        android:id=" @+id/mylistview "        android:layout_width=" Wrap_content "        android:layout_height= "Wrap_content"/></relativelayout>



Package Com.flyou.hellomap;import Java.util.arraylist;import Java.util.list;import android.app.activity;import Android.os.bundle;import Android.view.keyevent;import Android.widget.arrayadapter;import Android.widget.ListView; Import Android.widget.toast;import Com.baidu.mapapi.sdkinitializer;import Com.baidu.mapapi.search.busline.buslineresult;import com.baidu.mapapi.search.busline.BusLineResult.BusStation; Import Com.baidu.mapapi.search.busline.buslinesearch;import com.baidu.mapapi.search.busline.BusLineSearchOption; Import Com.baidu.mapapi.search.busline.ongetbuslinesearchresultlistener;import Com.baidu.mapapi.search.core.cityinfo;import Com.baidu.mapapi.search.core.poiinfo;import Com.baidu.mapapi.search.core.searchresult;import Com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener; Import Com.baidu.mapapi.search.poi.poicitysearchoption;import Com.baidu.mapapi.search.poi.poidetailresult;import Com.baidu.mapapi.search.poi.poiresult;import com.baidu.mapapi.search.poi.poisearch;public CLASS Busmapactivity extends Activity {private int totalpages = 0;  Private ListView ListView = null;  Private Poisearch Poisearch;  private int currentpage = 0;  Arrayadapter<string> adapter = null; protected String Buslineid;  Private Buslinesearch Buslinesearch;    @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Initialize the context information before using each component of the SDK, passing in ApplicationContext//Note that the method is implemented Sdkinitializer.initialize before the method is Setcontentview (    Getapplicationcontext ());    Setcontentview (R.layout.activity_index);    ListView = (ListView) Findviewbyid (R.id.mylistview);    The first step is to create a poi retrieval instance Poisearch = Poisearch.newinstance ();        The third step, set up the POI Retrieval listener; Poisearch.setongetpoisearchresultlistener (Poilistener);    The first step is to create a busline retrieval instance Buslinesearch = Buslinesearch.newinstance (); The third step, set <span style= "Font-family:arial, Helvetica, Sans-serif;" >busline</span><span style= "font-family:arial, Helvetica, Sans-serif;" > Search listener; &lT;/span> Buslinesearch.setongetbuslinesearchresultlistener (Buslinelistener); } <span style= "color: #ff0000;"  > Ongetbuslinesearchresultlistener buslinelistener =new ongetbuslinesearchresultlistener () {@Override public      void Ongetbuslineresult (Buslineresult result) {String title;      List<busstation> stations = Result.getstations ();      List<string> datas=new arraylist<string> ();        for (Busstation busstation:stations) {title = Busstation.gettitle ();      Datas.add (title); }</span> Listview.setadapter (New arrayadapter<string> (Busmapactivity.this, Android).    R.layout.simple_list_item_1, datas));  }  }; The second step is to create a POI retrieval listener; Ongetpoisearchresultlistener Poilistener = new Ongetpoisearchresultlistener () {public void Ongetpo Iresult (poiresult result) {//Get POI Search Result if (result = = NULL | | result.error = = SearchResult.ERRORNO.RESULT_NOT_F Ound) {Toast.maketext (busmapactivity.this, "not foundResult ", Toast.length_long). Show ();      Return        } if (Result.error = = SearchResult.ERRORNO.NO_ERROR) {list<poiinfo> Allpoi = Result.getallpoi ();        TotalPages = Result.gettotalpagenum ();        string[] datas = new STRING[10]; Traverse all poi to find the POI <span style= "color: #ff0000;" In the bus line type. > For (poiinfo poi:result.getAllPoi ()) {if (Poi.type = = PoiInfo.POITYPE.BUS_LINE | | Poi.type = = PoiInfo.POITYPE.SUBWAY_LINE) {//indicates that the POI is a bus information, gets the UID of the bar Buslineid = Poi.ui                  D              Break }}//The following code is used to initiate the retrieval of code, defining listeners and setting listeners in a manner similar to the buslinesearch in the POI. Searchbusline (New Buslinesearch Option (). City ("Kaifeng"). UID (Buslineid)));</span>} if (Result.error = = Searchres Ult. Errorno.        Ambiguous_keyword) {//When the input keyword is not found in this city, but when found in other cities, returns the list of cities that contain the keyword information String strinfo = "on"; for (Cityinfo CityInfo:result.getSuggestCityLisT ()) {strinfo + = cityinfo.city;        Strinfo + = ",";        } Strinfo + = "Find results";      Toast.maketext (Busmapactivity.this, Strinfo, Toast.length_long). Show ();  }} public void Ongetpoidetailresult (Poidetailresult result) {//Get Place Details page search result}};    @Override protected void OnDestroy () {Super.ondestroy ();  Execute Mmapview.ondestroy () when activity executes OnDestroy, implement map life cycle management Poisearch.destroy ();    } @Override protected void Onresume () {super.onresume (); Executes Mmapview when the activity executes Onresume.    Onresume (), implementing the Map life cycle management} @Override protected void OnPause () {super.onpause (); Executes Mmapview when the activity executes OnPause. OnPause (), Implementing Map life cycle Management} @Override public boolean onKeyDown (int keycode, keyevent event) {switch (keycode) {CA         SE keyevent.keycode_menu:/** * Range retrieval//This is the range latlngbounds.builder B = new Latlngbounds.builder (); * B.include (New latlng (39.976446, 116.320331)); B.include (NEW * LATLNG (39.900766, 116.32838)); B.include (New LATLNG (39.910065, * 116.491081));         B.include (New Latlng (39.976004, 116.475558)); * Latlngbounds build = B.build (); Fourth step, initiate the search request; * Poisearch.searchinbound (NEW * poiboundsearchoption (). Bound (build). Keyword * ("gourmet"         ). Pagenum (CurrentPage)); */<span style= "color: #ff0000;" > poisearch.searchincity ((New Poicitysearchoption ()). City ("Kaifeng"). Keyword ("the"). Pagenum (CurrentPage)         );</span>/** * Poisearch.searchnearby (New poinearbysearchoption (). Keyword ("university") *. Location (new latlng (34.82336,114.31496)). RADIUS (3000) *),//Can be set for the coordinates of the positioning */currentpage++        ;        if (currentpage = = totalpages) {currentpage = 0;    } break;  } return Super.onkeydown (KeyCode, event); }}

Lines that run as a result of Kaifeng 33-way





Search results for Baidu



"Public transportation information Retrieval" of Baidu Map development

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.