Study Notes for Android: Baidu map (search around POI)

Source: Internet
Author: User

Poi search can be performed in three ways: search within earchinbounds by range and search term, search within earchincity by city poi, and search around within earchnearby.

The following uses the peripheral search as an example to describe how to search and display the covering poioverlay:

Public intPoisearchnearby(Java. Lang. String key, geopoint PT,
Int radius)

Initiate peripheral search based on the center point, radius, and search term.

Asynchronous function, which returns the ongetpoiresult method notification of the result in mksearchlistener.
Parameters:

Key-Keyword
Pt-central point geographic coordinates
Radius-radius, in meters
Return Value:

0 is returned for success; otherwise-1 is returned.

Demo: Search for KFC restaurants within 5000 of Tiananmen Square


mMKSearch.poiSearchNearBy("KFC", new GeoPoint((int) (39.915 * 1E6), (int) (116.404 * 1E6)), 5000);




Implement ongetpoiresult of mysearchlistener and display the search result:

public void onGetPoiResult(MKPoiResult result, int type, int iError) {    if (result == null) {        return;    }    PoiOverlay poioverlay = new PoiOverlay(MyMapActivity.this, mMapView);    poioverlay.setData(result.getAllPoi());    mMapView.getOverlays().add(poioverlay);}


Specific implementation:
Package xiaosi. baidumap; import android. OS. bundle; import COM. baidu. mapapi. bmapmanager; import COM. baidu. mapapi. geopoint; import COM. baidu. mapapi. mkaddrinfo; import COM. baidu. mapapi. mkdrivingrouteresult; import COM. baidu. mapapi. mkpoiresult; import COM. baidu. mapapi. mksearch; import COM. baidu. mapapi. mksearchlistener; import COM. baidu. mapapi. mktransitrouteresult; import COM. baidu. mapapi. mkwalkingrouteresult; imp Ort com. baidu. mapapi. mapactivity; import COM. baidu. mapapi. mapcontroller; import COM. baidu. mapapi. mapview; import COM. baidu. mapapi. poioverlay; public class baidumapactivity extends mapactivity {/** called when the activity is first created. */private bmapmanager mapmanager = NULL; private string key = "1b79478da01f7800aea8602517a6d89b38151105"; private mapview = NULL; @ overridepublic void oncreate (Bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); mapmanager = new bmapmanager (getapplication (); mapmanager. init (Key, null); super. initmapactivity (mapmanager); mapview = (mapview) findviewbyid (R. id. mapsview); mapview. setbuiltinzoomcontrols (true); // set to enable the built-in zoom control mapcontroller = mapview. getcontroller (); // get control of mmapview, which can be used to control and drive translation and scaling of mapcontroller. Setzoom (12); // set the map zoom level mksearch = new mksearch (); mksearch. init (mapmanager, new mysearchlistener (); // note that only one mksearchlistener is supported. The last setting prevails in mksearch. poisearchnearby ("KFC", new geopoint (INT) (39.915*1e6), (INT) (116.404*1e6), 5000 );} public class mysearchlistener implements mksearchlistener {public void ongetaddrresult (mkaddrinfo arg0, int arg1) {} public void ongetdrivingrouteresult (mkdr Ivingrouteresult arg0, int arg1) {} public void ongetpoiresult (mkpoiresult arg0, int arg1, int arg2) {If (arg0 = NULL) {return ;} poioverlay = new poioverlay (baidumapactivity. this, mapview); poioverlay. setdata (arg0.getallpoi (); mapview. getoverlays (). add (poioverlay);} public void ongettransitrouteresult (mktransitrouteresult arg0, int arg1) {} public void ongetwalkingrouteresult (mkwalkingrou Teresult arg0, int arg1) {}@ overrideprotected Boolean isroutedisplayed () {return false ;}@ overrideprotected void ondestroy () {If (mapmanager! = NULL) {mapmanager. Destroy (); mapmanager = NULL;} super. ondestroy () ;}@ overrideprotected void onpause () {If (mapmanager! = NULL) {mapmanager. Stop () ;}super. onpause () ;}@ overrideprotected void onresume () {If (mapmanager! = NULL) {mapmanager. Start () ;}super. onresume ();}}






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.