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

Source: Internet
Author: User

In the previous article, we introduced how to add things to a map. This article will show you how to search for routes within the MAP range.

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

First, we will officially start to introduce new knowledge points. First, we will introduce how to search maps.

The map search is actually very simple. You only need to customize a mysearchlistener to implement the mksearchlistener API provided by Baidu map. Of course, you must implement the methods in the class.

// Implement the search object public class mysearchlistener implements mksearchlistener {@ overridepublic void ongetaddrresult (mkaddrinfo arg0, int arg1) {}@ overridepublic void ongetbusdetailresult (optional arg0, int arg1) {}@ overridepublic void ongetdrivingrouteresult (mkdrivingrouteresult result, int type) {// callback response to the called search method if (result = NULL) {return ;} routeoverlay = new routeoverlay (baidu_suyiactivity.this, mapview); // The reason for the entry in the routeoverlay is that we only need to return the first line routeoverlay. setdata (result. getplan (0 ). getroute (0); mapview. getoverlays (). add (routeoverlay); mapview. invalidate () ;}@ overridepublic void ongetpoidetailsearchresult (INT arg0, int arg1) {}@ overridepublic void ongetpoiresult (mkpoiresult result, int type, int ierror) {// callback response to the called search method if (result = NULL) {return;} poioverlay = new poioverlay (baidu_suyiactivity.this, mapview); poioverlay. setdata (result. getallpoi (); mapview. getoverlays (). add (poioverlay); mapview. invalidate () ;}@ overridepublic void Merge (string arg0, int arg1) {}@ overridepublic void Merge (mksuggestionresult arg0, int arg1) {}@ overridepublic void Merge (mktransitrouteresult arg0, int arg1) {}@ overridepublic void ongetwalkingrouteresult (mkwalkingrouteresult arg0, int arg1 ){}}

Do not forget to define the search object, which is defined at the beginning of the class.

// Define the search object private mksearch;

Then add the following code to the oncreate method:

For example, if I want to search around M toilets in the center of Tiananmen Square

Mksearch. shortearchnearby ("restroom", new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6), 5000 );

I will not list them here.

// V4.00 // mapcontroller. setzoom (14); // search for objects within the MAP range // mksearch = new mksearch (); // mksearch. init (bmapmanager, new mysearchlistener (); // This method searches the surrounding content based on the central point. // mksearch. earchnearby ("restroom", new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6), 5000 );

Second: We will introduce you to the search of driving routes.

The first step is to define a mysearchlistener like "First: search within a map" to implement the mksearchlistener API provided by Baidu map. Of course, the methods in the class must be implemented.

Then add the following code to the oncreate method:

// V5.00 mapcontroller. setzoom (14); // 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 coordinates of end = new mkplannode (); end.pt = new geopoint (40057031,2017307852); // route priority of mksearch. setdrivingpolicy (mksearch. ebus_time_first); // call the route callback method mksearch. drivingsearch (null, start, null, end );

Note that two vertices, starting point and ending point, must be defined at the top of the class.

// Define a start point private mkplannode start; // define an end point private mkplannode end;

There are two points to note: the first is the line priority.

There are multiple types of options in the mksearch. setdrivingpolicy () method. The APIS provided by Baidu map include the following selection objects --> official documentation address

Pay attention to the parameters in the drivingsearch method.

Finally, I want to give you a brief explanation. In fact, what I write here is just the fur in my skin. It is only convenient for those who are at the same level as me and learn from each other to grow together, please don't laugh at the cool and cool.

I hope you will understand that tomorrow is a wonderful day when you go to bed every day ......

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.