百度地图加强_搜索_poiSearchNearBy(圆形区域内检索信息)
|
核心代码:
package cn.zengfansheng.mybaidumap.search;
import android.os.Bundle;
import android.widget.Toast;
import cn.zengfansheng.mybaidumap.BaseActivity;
import cn.zengfansheng.mybaidumap.BaseMKMapViewListener;
import cn.zengfansheng.mybaidumap.BaseMkSearchListener;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.PoiOverlay;
import com.baidu.mapapi.search.MKPoiResult;
import com.baidu.mapapi.search.MKSearch;
import com.baidu.mapapi.search.MKSearchListener;
/**
* 圆形区域检索兴趣点
*/
public class PoiSearchNearByDemo extends BaseActivity {
private MKSearch mkSearch;
private MKSearchListener mkSearchListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
searchNearBy();
}
private void searchNearBy() {
mkSearch = new MKSearch();
// 1、初始化
mkSearchListener = new MyMKSearchListener();
mkSearch.init(mBMapMan, mkSearchListener);
// 2、按照圆形区域中心点范围检索兴趣点
int radius = 1000;
mkSearch.poiSearchNearBy("加油站", geoPoint, radius);
}
/**
* 搜索后的监听器
*/
private class MyMKSearchListener extends BaseMkSearchListener {
@Override
public void onGetPoiResult(MKPoiResult result, int type, int iError) {
super.onGetPoiResult(result, type, iError);
if (iError == 0 && result != null) {
PoiOverlay poiOverlay = new PoiOverlay(PoiSearchNearByDemo.this, mMapView); // 1、获取Overlays集合,并添加一个overlay到集合中去
mMapView.getOverlays().add(poiOverlay); // 2、设置overlay数据
poiOverlay.setData(result.getAllPoi());
// MapView信息点点击事件
mapController.enableClick(true);
mMapView.regMapViewListener(mBMapMan,new BaseMKMapViewListener() {
@Override
public void onClickMapPoi(MapPoi mapPoiInfo) {
super.onClickMapPoi(mapPoiInfo);
Toast.makeText(getApplicationContext(), mapPoiInfo.strText, 0).show();
}
});
// 3、刷新MapView界面
mMapView.refresh();
}
}
}
} |
结果: |