Android Baidu Map API integration three "search"

Source: Internet
Author: User

Book pick up the back ↑

First, the basic map interface address: http://www.cnblogs.com/dhr125/p/5969980.html

Second, map location address: http://www.cnblogs.com/dhr125/p/5970118.html

search Function

1. Adding a layout to an XML file

1<LinearLayout2Android:layout_width= "Match_parent"3android:layout_height= "Wrap_content" >4<EditText5Android:layout_width= "0dip"6android:layout_height= "Wrap_content"7android:layout_weight= "1"8Android:hint= "Please enter your search address"9Android:id= "@+id/etsearch"/>Ten<Button OneAndroid:layout_width= "Wrap_content" Aandroid:layout_height= "Wrap_content" -android:text= "Search" -Android:id= "@+id/btnsearch"/> the</LinearLayout>

2. Follow the location, locate the Poisearchdemo.java, and prepare to copy the code

3. Copy the following code into OnCreate and let the activity implement Ongetpoisearchresultlistener

Initialize the search module, register the search event listener    mpoisearch = Poisearch.newinstance ();    Mpoisearch.setongetpoisearchresultlistener (this);

4. The following 3 methods are rewritten after implementation

1 @Override2      Public voidOngetpoiresult (Poiresult poiresult) {3 4     }5 6 @Override7      Public voidOngetpoidetailresult (Poidetailresult poidetailresult) {8 9     }Ten  One @Override A      Public voidOngetpoiindoorresult (Poiindoorresult poiindoorresult) { -  -}

5. Add code to the overridden method Ongetpoiresult, and then modify the code based on the error

1  if(Poiresult = =NULL|| Poiresult.error = =SearchResult.ERRORNO.RESULT_NOT_FOUND) {2Toast.maketext (mainactivity. This, "Results not Found", Toast.length_long)3 . Show ();4             return;5         }6         if(Poiresult.error = =SearchResult.ERRORNO.NO_ERROR) {7 mbaidumap.clear ();8Poioverlay overlay =NewMypoioverlay (mbaidumap);9 Mbaidumap.setonmarkerclicklistener (overlay);Ten Overlay.setdata (poiresult); One Overlay.addtomap (); A Overlay.zoomtospan (); - Shownearbyarea (center, RADIUS); -  the             return; -}

6. Locate two classes in the following location and copy to the project

7. Adding code to the project

1 Private classMypoioverlayextendsPoioverlay {2 3          PublicMypoioverlay (Baidumap baidumap) {4             Super(BAIDUMAP);5         }6 7 @Override8          Public BooleanOnpoiclick (intindex) {9             Super. Onpoiclick (index);TenPoiinfo poi =Getpoiresult (). Getallpoi (). get (index); One             //if (poi.hascaterdetails) { AMpoisearch.searchpoidetail ((Newpoidetailsearchoption ()) - . Poiuid (Poi.uid)); -             // } the             return true; -         } -}
  1  /**   2   * draw the range retrieved by the perimeter   3   *   @param   center   4   *   @param   radius   5  */  6  public  void  shownearbyarea (latlng Center, int   radius) {  7  16 }  

8. Add the following two member variables to a member location

  LATLNG center = null;  int radius = 5000;

Also, after locating the Mylocationlistenner in the SDK listener function, instantiate the center, as follows

@Override          Public void onreceivelocation (bdlocation location) {            //  map view is not processed after the newly received position is destroyed            if NULL NULL ) {                return;            }             = new Latlng (Location.getlatitude (), Location.getlongitude ());

9. Find a custom Input box and button to listen

1Etsearch =(EditText) Findviewbyid (r.id.etsearch);2Button btnsearch =(Button) Findviewbyid (r.id.btnsearch);3Btnsearch.setonclicklistener (NewView.onclicklistener () {4 @Override5              Public voidOnClick (View v) {6Poinearbysearchoption nearbysearchoption =Newpoinearbysearchoption (). Keyword (etsearch.gettext ()7 . toString ()). SortType (Poisorttype.distance_from_near_to_far). Location (center)8. Radius (RADIUS). Pagenum (10);9 Mpoisearch.searchnearby (nearbysearchoption);Ten             } One});

Above, you can implement the search function

  

Android Baidu Map API integration three "search"

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.