Enquiry line details-million bus

Source: Internet
Author: User

Requirements:
Enter the bus line, example: 3 way. Get all of the 3-way car through the site name, first last train, fares.

How to solve
The bus line is also a poi. There are ready-made functions to get the line condition

How to solve
Mainly used in 3 classes, Poisearch Buslinesearch Buslineresult

Poisearch is based on the keyword to get poi details, not much to say, look through the document.

Buslinesearch is based on the UID to get the details of the line, the results of Poisearch generally have two, bus travel and return.

Buslineresult is the line class, which contains all the lines of the site, the line of the first time of the car. (The price of this property I did not find, I set a unified two pieces).

Code
Poisearch related Code

Msearch.searchincity (New Poicitysearchoption ()). City ("Suzhou")
            . Keyword (caredittext.gettext (). toString ()));
Above and below are related public

void Ongetpoiresult (poiresult result) {
    if (result = = NULL | | Result.error! = SEARCHRESULT.ERR Orno.no_error) {
        return;
    }

Buslineidlist.clear ();
For (Poiinfo Poi:result.getAllPoi ()) {
    if (Poi.type = = PoiInfo.POITYPE.BUS_LINE
        | | poi.type = poiinfo.poitype. Subway_line) {

        buslineidlist.add (poi.uid);
    }
}
LOG.D ("Buslineidlist", buslineidlist.size () + "");
Searchnextbusline ("Suzhou", Buslineidlist.get (0));
}

Several parameters of poisearch.searchincity are specified according to their needs.

Msearch.setongetpoisearchresultlistener (this), there are 2 methods of monitoring Ongetpoidetailresult Ongetpoiresult

Here I used the ongetpoiresult to get the UID of this poi.

Searchnextbusline ("Suzhou", Buslineidlist.get (0)); This method is called in Ongetpoiresult to ensure that the bus's UID is not queried until the bus line details are obtained.

Buslinesearch related Code

 Mbuslinesearch = Buslinesearch.newinstance (); The single example obtains the object Mbuslinesearch.setongetbuslinesearchresultlistener (this); Set listener public void Searchnextbusline (String city,string uid) {//Enable search Mbuslinesearch.searchbusline (new Busli
Nesearchoption (). City). UID (UID)); }//The results of the listener. Code is not difficult, easy to read public void Ongetbuslineresult (Buslineresult result) {arraylist<string> buslinestation = new Arraylis
    T<string> (); TODO auto-generated Method Stub if (result = = NULL | | Result.error! = SearchResult.ERRORNO.NO_ERROR) {Retu
    Rn
    } route = result;

    LOG.D ("Result", Route.getbuslinename ()); for (int i = 0; i < result.getstations (). Size (); i++) {Buslinestation.add (Route.getstations (). get (i). GetTitle (
        ));
    LOG.D ("StationName", Buslinestation.get (i));

    } stationarraylist = Buslinestation;
    startstation = stationarraylist.get (0);
    Laststation = Stationarraylist.get (Stationarraylist.size ()-1); Here is the one-digit hours, minutesAdd 0 to the front of the clock.
    Example: 9:9-09:09 FirstClass = "First Class" + Busutils.addzerobeforetime (Route.getstarttime ());
    Lastclass = "Last Shift" + Busutils.addzerobeforetime (Route.getendtime ());
    Price = "2.0 Yuan";

    Buslinename = Route.getbuslinename ();
    Intent Intent = new Intent (getactivity (), stationlistactivity.class);
    Intent.putextra ("Startstation", startstation);
    Intent.putextra ("FirstClass", FirstClass);
    Intent.putextra ("Lastclass", Lastclass);
    Intent.putextra ("Price", price);
    Intent.putextra ("Laststation", laststation);
    Intent.putextra ("Stationarraylist", stationarraylist);
    Intent.putextra ("Buslinename", buslinename);
    Intent.putextra ("Bulinenum", buslinenum);

StartActivity (Intent);
 }

After the

jumps to the new activity, the resulting data will be processed in the ListView. Return, then call again in order. Of course, this method can be encapsulated to better call.

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.