Android Baidu Map hotspot Search (ii)

Source: Internet
Author: User

1. Related Interfaces and methods:

①ongetpoisearchresultlistener Interface Search Results monitoring

New Ongetpoisearchresultlistener () {      publicvoid  ongetpoiresult (poiresult result) {       // Get POI search results       }      publicvoid  ongetpoidetailresult (poidetailresult result) {       // Get Place Details page search results       }  };

② Creating a POI Search instance

  Poisearch    Mpoisearch  = Poisearch.newinstance ();    // Create a POI search instance

③ setting up POI search monitoring

  Mpoisearch.setongetpoisearchresultlistener (Poilistener);

④ initiating a search

   Mpoisearch.searchincity (new  poicitysearchoption ()          city//Search in the cities                                                    . Keyword (keyword)    //Keywords                                                    . Pagenum (Pagenum));   Pages

⑤poi more Search

Mpoisearch.searchpoidetail ((new poidetailsearchoption ()). Poiuid (UID));  Each entry in the list returned by the call to Searchincity contains the UID, which is taken out
The second method of the Ongetpoisearchresultlistener interface Ongetpoidetailresult
will return the search results here

⑥ releasing a POI search instance

   Mpoisearch.destroy ();    After the search is over, be sure to release

2. Attach my simple package code, directly into the configuration of the project can be directly called

 PackageCom.example.baidumapdemo;Importjava.util.List;ImportAndroid.content.Context;ImportAndroid.util.Log;ImportAndroid.widget.Toast;ImportCom.baidu.mapapi.search.core.CityInfo;ImportCom.baidu.mapapi.search.core.SearchResult;ImportCom.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;Importcom.baidu.mapapi.search.poi.PoiCitySearchOption;ImportCom.baidu.mapapi.search.poi.PoiDetailResult;ImportCom.baidu.mapapi.search.poi.PoiResult;ImportCom.baidu.mapapi.search.poi.PoiSearch;ImportCom.baidu.mapapi.search.sug.OnGetSuggestionResultListener;ImportCom.baidu.mapapi.search.sug.SuggestionResult;ImportCom.baidu.mapapi.search.sug.SuggestionResult.SuggestionInfo;ImportCom.baidu.mapapi.search.sug.SuggestionSearch;/** *  * @authorAdministrator * Ongetpoisearchresultlistener POI search Monitor*/ Public classBaidumappoisearchutilsImplementsongetpoisearchresultlistener,ongetsuggestionresultlistener{ PublicPoisearch Mpoisearch; PrivateSuggestionsearch Msuggestionsearch; //private Infowindow Minfowindow;        Private Staticbaidumappoisearchutils mpoisearchutils; Privatecontext Context; PrivateOnpoisearchresultcallback Monpoisearchresultcallback; PrivateOnsuggestionresultcallback Monsuggestionresultcallback; PrivateOngetpoidetailresultcallback Mongetpoidetailresultcallback; PrivateOnsearcherrorcallback Onsearcherrorcallback; PrivateBaidumappoisearchutils (Context context) {init (context); }         Public Staticbaidumappoisearchutils newinstance (context context) {if(Mpoisearchutils = =NULL) {mpoisearchutils=Newbaidumappoisearchutils (context); }        returnmpoisearchutils; }        Private voidinit (Context context) { This. Context =context; Mpoisearch= Poisearch.newinstance ();//Create a POI search instanceMsuggestionsearch =suggestionsearch.newinstance (); Mpoisearch.setongetpoisearchresultlistener ( This); Msuggestionsearch.setongetsuggestionresultlistener ( This); }        /*** Hot Search results *@paramMonpoisearchresultcallback*/     Public voidSetonpoisearchresultcallback (Onpoisearchresultcallback monpoisearchresultcallback) { This. Monpoisearchresultcallback =Monpoisearchresultcallback; }        /** Search Suggestions*/     Public voidSetonsuggestionresultcallback (Onsuggestionresultcallback monsuggestionresultcallback) { This. Monsuggestionresultcallback =Monsuggestionresultcallback; }        /*** Search Details *@paramMongetpoidetailresultcallback*/     Public voidSetongetpoidetailresultcallback (Ongetpoidetailresultcallback mongetpoidetailresultcallback) { This. Mongetpoidetailresultcallback =Mongetpoidetailresultcallback; }    /*** Search Error *@paramOnsearcherrorcallback*/     Public voidSetonsearcherrorcallback (Onsearcherrorcallback onsearcherrorcallback) { This. Onsearcherrorcallback =Onsearcherrorcallback; }     Public voidStartsearch (String city,string KeyWord,intpagenum) {mpoisearch.searchincity (Newpoicitysearchoption (). City (city) keyword (keyword)    . Pagenum (Pagenum)); } @Override Public voidOngetsuggestionresult (suggestionresult result) {if(Result = =NULL|| Result.error! =SearchResult.ERRORNO.NO_ERROR) {            if(Onsearcherrorcallback! =NULL) {onsearcherrorcallback.ongetpoidetailresult (); }            return; }        if(Monsuggestionresultcallback! =NULL) {Monsuggestionresultcallback.onsuggestionresult (result.getallsuggestions ()); }} @Override Public voidOngetpoidetailresult (poidetailresult result) {if(Result = =NULL|| Result.error = =SearchResult.ERRORNO.RESULT_NOT_FOUND) {Toast.maketext (context,"Results not Found", Toast.length_short). Show (); return; }        if(Mongetpoidetailresultcallback! =NULL) {Mongetpoidetailresultcallback.ongetpoidetailresult (result); }} @Override Public voidOngetpoiresult (poiresult result) {if(Result = =NULL|| Result.error! =SearchResult.ERRORNO.NO_ERROR) {Toast.maketext (context,"Results not Found", Toast.length_short). Show (); return; }        if(Monpoisearchresultcallback! =NULL) {Monpoisearchresultcallback.onpoisearchresult (result); }        if(Result.error = =SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) {String Strinfo= "in";  for(Cityinfo c:result.getsuggestcitylist ()) {Strinfo+=c.city; Strinfo+= ","; } strinfo+ = "Find Results"; LOG.E ("TAG", Strinfo); }    }         Public Interfaceonpoisearchresultcallback{ Public voidOnpoisearchresult (poiresult result); }     Public Interfaceonsuggestionresultcallback{ Public voidOnsuggestionresult (list<suggestioninfo>list); }     Public Interfaceongetpoidetailresultcallback{ Public voidOngetpoidetailresult (poidetailresult result); }     Public Interfaceonsearcherrorcallback{ Public voidOngetpoidetailresult (); }     Public voidOnDestroy () {Mpoisearch.destroy ();    Msuggestionsearch.destroy (); }}

Baidu Map first introduced to this, there is time to attach the map location mark.

Android Baidu Map hotspot Search (ii)

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.