Detailed search of bus routes
How to retrieve bus roadmap of a city
Case study: Search for routes of 717 of Beijing public transit routes
Main Code:
Import COM. baidu. mapapi. bmapmanager; import COM. baidu. mapapi. mkaddrinfo; import COM. baidu. mapapi. mkbuslineresult; import COM. baidu. mapapi. mkdrivingrouteresult; import COM. baidu. mapapi. mkgenerallistener; import COM. baidu. mapapi. mkpoiinfo; import COM. baidu. mapapi. mkpoiresult; import COM. baidu. mapapi. mksearch; import COM. baidu. mapapi. mksearchlistener; import COM. baidu. mapapi. mksuggestionresult; import COM. baidu. Mapapi. mktransitrouteresult; import COM. baidu. mapapi. mkwalkingrouteresult; import COM. baidu. mapapi. mapactivity; import COM. baidu. mapapi. mapview; import COM. baidu. mapapi. routeoverlay; import COM. baidu. mapapi. transitoverlay; import android. OS. bundle; import android. widget. toast; public class mainactivity extends mapactivity {// Add a control related to Baidu map private mapview; // the engine that loads the map private bmapmanager bmapmanage R; // key private string keystring = "8c426377b3526b6bf3672c9ba3bb544d1e8289cd "; // Private mksearch is used for location search, peripheral search, range search, public transport search, driving and walking search. @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); mapview = (mapview) This. findviewbyid (R. id. bmapview); bmapmanager = new bmapmanager (mainactivity. this); // The Key bmapmana must be loaded. Ger. init (keystring, new mkgenerallistener () {public void ongetpermissionstate (INT arg0) {} public void ongetnetworkstate (INT arg0) {If (arg0 = 300) {toast. maketext (mainactivity. this, "The entered key is incorrect. Please verify it !! ", 1 ). show () ;}}); this. initmapactivity (bmapmanager); // The Query Class mksearch = new mksearch (); mksearch. init (bmapmanager, new mysearchlistener (); // city name, keyword mksearch. earchincity ("Beijing", "300");} public class mysearchlistener implements mksearchlistener {public void ongetaddrresult (mkaddrinfo arg0, int arg1) {// todo auto-generated method stub} public void ongetbusdetailresult (mkbuslineresult Arg0, int arg1) {// todo auto-generated method stub if (arg0 = NULL | arg1! = 0) {toast. maketext (mainactivity. This, "Sorry, no results found !! ", 1 ). show (); return;} routeoverlay = new routeoverlay (mainactivity. this, mapview); routeoverlay. setdata (arg0.getbusroute (); // obtain the bus route map mapview. getoverlays (). clear (); // clear the ID of the bus stop mapview. getoverlays (). add (routeoverlay); mapview. invalidate (); // use an animation to describe the mapview of the bus stop. getcontroller (). animateto (arg0.getbusroute (). getstart ();} public void ongetdrivingrouteresult (mkdrivingrouteresult arg0, in T arg1) {// todo auto-generated method stub}/*** get the UID of the bus route map, in addition, the UID is used to search Bus Route details */Public void ongetpoiresult (mkpoiresult result, int type, int ierror) {// todo auto-generated method stub if (result = NULL | ierror! = 0) {toast. maketext (mainactivity. this, "Sorry, no results found", 1 ). show (); return;} // defines the description class mkpoiinfo = NULL for the bus route map; int totalpoinum = result. getnumpois (); // obtain the number of bus stops in the locally retrieved bus route map for (INT I = 0; I <totalpoinum; I ++) {mkpoiinfo = result. getpoi (I); // 2 if (mkpoiinfo. epoitype = 2) {break;} mksearch. buslinesearch ("Beijing", mkpoiinfo. UID);} public void ongetrgc1_urlresult (string arg0, int arg1) {// todo aut O-generated method stub} public void initialize (mksuggestionresult arg0, int arg1) {// todo auto-generated method stub} public void ongettransitrouteresult (mktransitrouteresult arg0, int arg1) {// todo auto-generated method stub if (arg0 = NULL) {return;} transitoverlay transioverlay = new transitoverlay (mainactivity. this, mapview); transioverlay. setdata (arg0.getplan (0); mapview. geto Verlays (). add (transioverlay); mapview. invalidate ();} public void ongetwalkingrouteresult (mkwalkingrouteresult arg0, int arg1) {// todo auto-generated method stub} @ override protected void ondestroy () {super. ondestroy (); If (bmapmanager! = NULL) {bmapmanager. Destroy (); bmapmanager = NULL ;}@override protected void onresume () {super. onresume (); If (bmapmanager! = NULL) {bmapmanager. Start () ;}@ override protected void onpause () {super. onpause (); If (bmapmanager! = NULL) {bmapmanager. Stop () ;}@ override protected Boolean isroutedisplayed () {return false ;}}