004 go to the android project of mobile development (Baidu map: walking route bus transfer route bus detailed route)

Source: Internet
Author: User

This post is based on the logic of the previous post.

003 go to the android project of mobile development (Baidu map: search by map and driving route)

If you do not understand anything, please refer to the previous post

002 hands-on Android project of mobile development (Baidu map: Add annotation to map)

If you have any questions, read the first article.

001 practical implementation of Android projects for mobile development (Baidu map: Building a Baidu map development environment)

Please note that when reprinting an article, please indicate the source.

Http://blog.csdn.net/shuaiyinoo》thank you


Well, today we will bring you three technical points,

First technical point: Route

Based on our previous experience, we need to add the following search code to the oncreate method in the first step of searching for a route.

// 6.0 search for the route // mapcontroller. setzoom (12); // search for objects within the MAP range // mksearch = new mksearch (); // mksearch. init (bmapmanager, new mysearchlistener (); // specify the first coordinate // start = new mkplannode (); // start.pt = new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6); // specify the Second coordinate. // end = new mkplannode (); // end.pt = new geopoint (40057031,2017307852); // method for setting the callback route // mksearch. walkingsearch (null, start, null, end );

Then define a mysearchlistener implements mksearchlistener

Implement the ongetwalkingrouteresult method in the interface

@ Overridepublic void ongetwalkingrouteresult (mkwalkingrouteresult result, int type) {// calls back the called search method and responds if (result = NULL) {return ;} routeoverlay = new routeoverlay (baidu_suyiactivity.this, mapview); routeoverlay. setdata (result. getplan (0 ). getroute (0); mapview. getoverlays (). add (routeoverlay); // refresh the map mapview. invalidate ();}


Second technical point: Bus Transfer route

The first step and the second step

// 7.0 search for the bus transfer route // mapcontroller. setzoom (12); // search for objects within the MAP range // mksearch = new mksearch (); // mksearch. init (bmapmanager, new mysearchlistener (); // specify the first coordinate // start = new mkplannode (); // start.pt = new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6); // specify the Second coordinate. // end = new mkplannode (); // end.pt = new geopoint (40057031,2017307852); // method for setting the callback route // mksearch. transitsearch ("Beijing", start, end );

@ Overridepublic void ongettransitrouteresult (mktransitrouteresult result, int type) {// callback method of public transit transfer if (result = NULL) {return;} transitoverlay = new transitoverlay (transport, mapview); transitoverlay. setdata (result. getplan (0); mapview. getoverlays (). add (transitoverlay); // refresh the map mapview. invalidate ();}


Third technical point: Bus Route details

The search of bus routes is a little more complex.

The first step remains unchanged.

// 8.0 search mapcontroller for the bus route details. setzoom (12); // search for objects within the MAP range mksearch = new mksearch (); mksearch. init (bmapmanager, new mysearchlistener (); // method for setting the callback route mksearch. poisearchincity ("Beijing", "300 ");

Step 2 first implement this method in the interface

@ Overridepublic void ongetpoiresult (mkpoiresult result, int type, int ierror) {// callback response to the called search method // v8.00if (result = NULL | ierror! = 0) {toast. maketext (baidu_suyiactivity.this, "sorry, you cannot find the result", 2 ). show (); Return ;}// define a bus route map description class mkpoiinfo = NULL; // get the bus route map's total site int totalpoinum = result. getnumpois (); For (INT I = 0; I <totalpoinum; I ++) {mkpoiinfo = result. getpoi (I); If (mkpoiinfo. epoitype = 2) {break; // if the road map of the bus is returned, return} mksearch. buslinesearch ("Beijing", mkpoiinfo. UID );}

Step 3 and then implement the following method

@ Overridepublic void ongetaddrresult (mkaddrinfo arg0, int arg1) {}@ overridepublic void ongetbusdetailresult (mkbuslineresult result, int type) {If (result = NULL | type! = 0) {toast. maketext (baidu_suyiactivity.this, "sorry, you cannot find the result", 2 ). show (); return;} routeoverlay = new routeoverlay (baidu_suyiactivity.this, mapview); routeoverlay. setdata (result. getbusroute (); // clear all bus information mapview. getoverlays (). clear (); mapview. getoverlays (). add (routeoverlay); mapview. invalidate (); mapview. getcontroller (). animateto (result. getbusroute (). getstart ());}

This completes the three knowledge points.

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.