Baidu map-follow-up Route Search

Source: Internet
Author: User

How to mark Route Search and routeoverlay

In actual development, we need to mark the optimal route

Case study: walking route from Tiananmen Square to Baidu Building

Main Code:

 
Import COM. baidu. mapapi. bmapmanager; import COM. baidu. mapapi. geopoint; import COM. baidu. mapapi. mkaddrinfo; import COM. baidu. mapapi. mkbuslineresult; import COM. baidu. mapapi. mkdrivingrouteresult; import COM. baidu. mapapi. mkgenerallistener; import COM. baidu. mapapi. mkplannode; import COM. baidu. mapapi. mkpoiresult; import COM. baidu. mapapi. mksearch; import COM. baidu. mapapi. mksearchlistener; import COM. baidu. mapapi. m Ksuggestionresult; 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 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 ;// Key Private string keystring = "8c426377b3526b6bf3672c9ba3bb544d1e8289cd"; // Private mksearch is used for location search, peripheral search, range search, bus search, driving and walking search; // define a start point, private mkplannode start; private mkplannode end; @ 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 bmapmanager must be loaded. 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 (); // create a coordinate for the start point: Start = new mkplannode (); start.pt = new geopoint (INT) (39.915*1e6 ), (INT) (116.404*1e6); End = new mkplannode (); end.pt = new geopoint (40057031,2017307852); mksearch. walkingsearch (null, start, null, end);} public class mysearchlistener impl Ements 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} public void initialize (mkdrivingrouteresult arg0, int arg1) {// todo auto-generated method stub} public void ongetpoiresult (mkpoiresult result, int type, int Ier Ror) {// todo auto-generated method stub} public void ongetrgc1_urlresult (string arg0, int arg1) {// todo auto-generated method stub} public void ongetsuggestionresult (mksuggestionresult arg0, int arg1) {// todo auto-generated method stub} public void ongettransitrouteresult (mktransitrouteresult arg0, int arg1) {// todo auto-generated method stub} public void ongetwalkingrouteresult (mkw Alkingrouteresult arg0, int arg1) {// todo auto-generated method stub if (arg0 = NULL) {return;} routeoverlay = new routeoverlay (mainactivity. this, mapview); routeoverlay. setdata (arg0.getplan (0 ). getroute (0); mapview. getoverlays (). add (routeoverlay); mapview. invalidate () ;}@ 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 ;}}

 

 

 

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.