PS: Install a system for a day. The heart is haggard. Feel no More love.
Learning content:
1. Use Baidu Map to achieve POI search.
2. Short string sharing
3. Online Suggestion Enquiry
Baidu's map of the study is more than half. Ability to implement positioning, search for relevant information, achieve map control that's a big part of it. This is about how to achieve poi search. So what is poi.
Poi:poi Chinese translation as a point of interest. Fishing dry said in fact is around some KTV, hotel, restaurant, barber shop and so is a poi. After the premise of the basic positioning is achieved, search for nearby poi. So you can do something else. For example, to order a takeaway, Book a room and so on. These are based on POI search to be able to achieve.
Baidu SDK provides three kinds of POI search: Peripheral Search, area search, in-City search (Com.baidu.mapapi.search.poi).
Search is based on the above API, the implementation of POI search or need to be divided into several processes. First, you need to instantiate the object Poisearch.
Private Poisearch poisearch= poisearch.newinstance ();
You then need to set up a search method for Poisearch. The way is three of the above mentioned. Three ways to search are listed below, we can see the Baidu map of the results of the search page processing, so we need to set the page number of pages and the amount of pages per page when displaying.
/*** Search in the city, directly according to the contents of the input box to achieve POI search. */ Private voidCitysearch (intpage) { //Set Retrieval ParametersPoicitysearchoption citysearchoption =Newpoicitysearchoption (); Citysearchoption.city (Editcityet.gettext (). toString ());//CityCitysearchoption.keyword (Editsearchkeyet.gettext (). toString ());//Key WordsCitysearchoption.pagecapacity (15);//default per page 10 articleCitysearchoption.pagenum (page);//Number of pages//set the search method for Poisearch.poisearch.searchincity (citysearchoption); } /*** Scope Search, scope searches need to develop coordinates. The range is searched in a rectangular manner. */ Private voidBoundsearch (intpage) {poiboundsearchoption boundsearchoption=Newpoiboundsearchoption (); LATLNG Southwest=NewLATLNG (latitude-0.01, longitude-0.012);//SouthwestLATLNG Northeast =NewLATLNG (latitude + 0.01, longitude + 0.012);//TohokuLatlngbounds bounds =NewLatlngbounds.builder (). Include (southwest). Include (northeast). Build ();//get a geographic scope objectBoundsearchoption.bound (bounds);//Set POI search scopeBoundsearchoption.keyword (Editsearchkeyet.gettext (). toString ());//Retrieving Keywordsboundsearchoption.pagenum (page); Poisearch.searchinbound (boundsearchoption);//initiating a POI range retrieval request } /*** near search, range searches need to specify the center of the circle. Search in a circular manner. */ Private voidNearbysearch (intpage) {poinearbysearchoption nearbysearchoption=Newpoinearbysearchoption (); Nearbysearchoption.location (Newlatlng (latitude, longitude)); Nearbysearchoption.keyword (Editsearchkeyet.gettext (). toString ()); Nearbysearchoption.radius (1000);//retrieves the radius, in metersnearbysearchoption.pagenum (page); Poisearch.searchnearby (nearbysearchoption);//initiate a nearby search request}
By the way, we can make a search for poisearch. After specifying the search pattern, we need to specify the relevant listener after the retrieval. The settings for the listener are done through the Ongetpoisearchresultlistener of the API. This interface accepts Poiresult As a parameter, when the search is completed, callback the current interface, you can go to get our search results, the following is the implementation of POI lookup results monitoring.
Ongetpoisearchresultlistener Poisearchlistener =NewOngetpoisearchresultlistener () {//Get Poiresult@Override Public voidOngetpoiresult (Poiresult poiresult) {if(Poiresult.error = =SearchResult.ERRORNO.NO_ERROR) {bdmap.clear (); Mypoioverlay Poioverlay=NewMypoioverlay (BDMAP);//instantiates an Poioverlay object.Poioverlay.setdata (Poiresult);//set the Poioverlay data.Bdmap.setonmarkerclicklistener (Poioverlay);//Monitor settings when the marker is clicked.Poioverlay.addtomap ();//Add all the POI to the map.Poioverlay.zoomtospan (); Totalpage=Poiresult.gettotalpagenum (); Toast.maketext (poisearchactivity. This, "Total found" + poiresult.gettotalpoinum () + "points of interest, divided into" + totalpage + "page", Toast.length_short). Show (); } } //When you click on the overlay, query the detailed data information and return the data as a callback .@Override Public voidOngetpoidetailresult (Poidetailresult poidetailresult) {}};
Here we can see. This callback interface encapsulates two methods internally. One is a query for the POI results, and the other is a query for the POI's detailed results. Poi detailed results contain most of the current points of interest (such as POI name, geographic location, coordinate data, etc.). This is the result of the detailed results of the retrieval. The query for detailed results is based on poiresult. Therefore, two functions are encapsulated.
The POI detailed result query needs to pass the Poidetailresult object as the parameter to which the interface returns. This object is instantiated in the following way, This is the time to trigger a POI detail Query event when clicking on the POI. This allows you to complete queries for more information on POI based on POI queries.
classMypoioverlayextendsPoioverlay { PublicMypoioverlay (Baidumap arg0) {Super(arg0); } //retrieves the POI details. Get Poioverlay@Override Public BooleanOnpoiclick (intarg0) { Super. Onpoiclick (arg0); Poiinfo Poiinfo=Getpoiresult (). Getallpoi (). get (ARG0); Poisearch.searchpoidetail (Newpoidetailsearchoption (). Poiuid (Poiinfo.uid)); return true; } }
here, by using the functions provided internally by the Poioverlay class, we can say that all the overlay we get are added directly to the map. This is very convenient. We don't have to save the query data for a group of groups in the List<t> list. The data is then placed on the map by way of traversal. This can only be done directly by using the Addtomap () function in Poioverlay. If we want to remove these overlay we only need to call Removefrommap () You can remove them all. This makes the search results more convenient to display.
Finally, some minor details related to the problem. It's about the POI. Take our most familiar takeaway. It can locate a lot of poi, Not only independent shops but also in-house stores can be precisely located. Independent stores in the outside are easily searchable. And the store interior stores want to be located to the Baidu map of the store to apply for the Merchant center, fill in the store information, After the application is successful, these stores will naturally be able to be searched. If you do not apply, then there are some shops inside the mall can not be located. So much for the POI.
2. Short string sharing
Short-string sharing: Represents the location of the geolocation to be displayed as a URL. This URL was optimized by Baidu into a short URL string, it is a short string. We can share this short string by SMS, email, etc.
The implementation of short-string sharing is still very simple.
You first need to instantiate a short string of shared objects.
Private Shareurlsearch Shareurlsearch = Shareurlsearch.newinstance ();
Then set a short string to retrieve the listener.
/*** Short string search listener*/Ongetshareurlresultlistener Shareurlresultlistener=NewOngetshareurlresultlistener () {//poi details Share URL@Override Public voidOngetpoidetailshareurlresult (Shareurlresult arg0) {toast.maketext (poisearchactivity. This, "Detailed URL sharing:" +arg0.tostring (), Toast.length_short). Show (); } //request location information share URL@Override Public voidOngetlocationshareurlresult (Shareurlresult arg0) {toast.maketext (poisearchactivity. This, "url sharing:" +arg0.tostring (), Toast.length_short). Show (); } };
After setting up the retrieval listener, it is necessary to send the request to realize the short string data sharing.
Shareurlsearch.requestlocationshareurl (new locationshareurloption (). Location (poiinfo.location). Name (" Share point Name "). Snippet (" 123 ")); Shareurlsearch.requestpoidetailshareurl (new poidetailshareurloption () . Poiuid (Poiinfo.uid));
3. Online suggestion inquiry.
Read a blogger's blog, said the online advice query and short-string sharing is similar, the code is directly slightly. So he went on the internet for a while. It's quite the same, but it's pretty much the same, but let's just say the first thing you need to instantiate the object.
Suggestionsearch = suggestionsearch.newinstance (); Suggestionsearch.requestsuggestion (New Suggestionsearchoption (). Keyword ("Baidu"). City ("background")); Send Request
then set up the relevant listening.
/** * online suggestions * */ Ongetsuggestionresultlistener suggestionresultlistener = new Ongetsuggestionresultlistener () {@Override public void Ongetsuggestionresult ( Suggestionresult arg0) { // TODO Auto -generated method Stub toast.maketext (Poisearchactivity. This
I think the POI search is the key. Poi retrieval is the most important thing we want to do. The related listening Here I have set the very simple, directly using the Toast box to print. If there is a higher demand, we can go for customization.
Finally put a source code: Http://files.cnblogs.com/files/RGogoing/BDMap.rar
Android Learning notes using Baidu Map to achieve POI search