Adding a cover to a Baidu map and planning a two-point route

Source: Internet
Author: User

Final latlng LL = new latlng (latiide, longpolling );
Bitmapdescriptor descriptor = bitmapdescriptorfactory
. Fromresource (Marker );
Overlayoptions Options = new markeroptions (). Position (LL). Icon (
Descriptor );
Mbaidumap. addoverlay (options );

 

Route Planning:

Mmapview = (mapview) findviewbyid (R. Id. bmapview );
Mbaidumap = mmapview. getmap ();
Search = routeplansearch. newinstance ();
Search. setongetrouteplanresultlistener (listener );

// Two points to be planned
Plannode ST = plannode. withlocation (New latlng (39.931867, 116.395645 ));
Plannode ED = plannode. withlocation (New latlng (39.915267, 116.40355 ));

Search. mongoingsearch (New mongoingrouteplanoption (). From (ST). To (ed ));

Of course there are events:

Ongetrouteplanresultlistener listener = new ongetrouteplanresultlistener (){
Public void ongetwalkingrouteresult (walkingrouteresult result ){
// Obtain the walking route planning result
If (result = NULL | result. Error! = Searchresult. errorno. no_error ){
Toast. maketext (daohangactivity. This, "Sorry, no result found ",
Toast. length_short). Show ();
}
If (result. Error = searchresult. errorno. ambiguous_roure_addr ){
// The start or end point address is incorrect. You can use the following interface to obtain the recommended query information.
// Result. getsuggestaddrinfo ()
Return;
}
If (result. Error = searchresult. errorno. no_error ){

// Route = result. getroutelines (). Get (0 );
Walkingrouteoverlay overlay = new mydomainingrouteoverlay (
Mbaidumap );
Mbaidumap. setonmarkerclicklistener (overlay );
Routeoverlay = overlay;
Overlay. setdata (result. getroutelines (). Get (0 ));
Overlay. addtomap ();
Overlay. zoomtospan ();
}

}

Public void ongettransitrouteresult (transitrouteresult result ){
// Obtain the transit route planning result
}

Public void ongetdrivingrouteresult (drivingrouteresult result ){
// Obtain the driving route planning result
}

};
Custom start and end icons:

Private class mywalkingrouteoverlay extends walkingrouteoverlay {

Public mydomainingrouteoverlay (baidumap ){
Super (baidumap );
}

@ Override
Public bitmapdescriptor getstartmarker (){
If (usedefaulticon ){
Return bitmapdescriptorfactory. fromresource (R. drawable. icon_st );
}
Return NULL;
}

@ Override
Public bitmapdescriptor getterminalmarker (){
If (usedefaulticon ){
Return bitmapdescriptorfactory. fromresource (R. drawable. icon_en );
}
Return NULL;
}
}

 

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.