android POI搜索,附近搜索,周边搜索定位介绍
2024-08-24 05:19:04
POI搜索有三种方式。依据范围和检索词发起范围检索poiSearchInbounds。城市poi检索poiSearchInCity,周边检索poiSearchNearBy。
下以周边检索为例介绍怎样进行检索并显示覆盖物PoiOverlay:
public int poiSearchNearBy(java.lang.String key, title=Android%E5%B9%B3%E5%8F%B0/%E7%B1%BB%E5%8F%82%E8%80%83/GeoPoint" title="Android平台/类參考/GeoPoint" style="color:rgb(38,121,186); text-decoration:none">GeoPoint
int radius)
- 依据中心点、半径与检索词发起周边检索.
- 异步函数,返回结果在MKSearchListener里的onGetPoiResult方法通知
- 參数:
- key - 关键词
- pt - 中心点地理坐标
- radius - 半径。单位:米
- 返回:
- 成功返回0,否则返回-1
Demo: 检索天安门周边5000米之内的KFC餐厅
- mMKSearch.poiSearchNearBy("KFC", new GeoPoint((int) (39.915 * 1E6), (int) (116.404 * 1E6)), 5000);
实现MySearchListener的onGetPoiResult,并展示检索结果:
- 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);
- }
详细实现:
- 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;
- import 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 mapView = null;
- @Override
- public 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); // 设置启用内置的缩放控件
- MapController mapController = mapView.getController(); // 得到mMapView的控制权,能够用它控制和驱动平移和缩放
- mapController.setZoom(12); // 设置地图zoom级别
- MKSearch mKSearch = new MKSearch();
- mKSearch.init(mapManager, new MySearchListener());// 注意。MKSearchListener仅仅支持一个。以最后一次设置为准
- 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(MKDrivingRouteResult arg0, int arg1)
- {}
- public void onGetPoiResult(MKPoiResult arg0, int arg1, int arg2)
- {
- if (arg0 == null) {
- return;
- }
- PoiOverlay poioverlay = new PoiOverlay(BaiduMapActivity.this, mapView);
- poioverlay.setData(arg0.getAllPoi());
- mapView.getOverlays().add(poioverlay);
- }
- public void onGetTransitRouteResult(MKTransitRouteResult arg0, int arg1)
- {}
- public void onGetWalkingRouteResult(MKWalkingRouteResult arg0, int arg1)
- {}
- }
- @Override
- protected boolean isRouteDisplayed()
- {
- return false;
- }
- @Override
- protected void onDestroy()
- {
- if (mapManager != null)
- {
- mapManager.destroy();
- mapManager = null;
- }
- super.onDestroy();
- }
- @Override
- protected void onPause()
- {
- if (mapManager != null)
- {
- mapManager.stop();
- }
- super.onPause();
- }
- @Override
- protected void onResume()
- {
- if (mapManager != null)
- {
- mapManager.start();
- }
- super.onResume();
- }
- }
最新文章
- CSS动画与GPU
- Java学习笔记 06 数字格式化及数学运算
- HDU5853 Jong Hyok and String(二分 + 后缀数组)
- 如何单独启动wamp 中自带的MySQL
- poj3904
- 自定义控件(视图)2期笔记08:自定义控件之 9patch图说明
- ubuntu下安装多个jdk的切换命令update-alternatives
- UEP-下拉
- BZOJ_1833_[ZJOI2010]count 数字计数_数位DP
- Kubernetes系列02—Kubernetes设计架构和设计理念
- 第41章 CORS - Identity Server 4 中文文档(v1.0.0)
- swipe.js实现支持手拔与自动切换的图片轮播
- azkaban工作流调度器及相关工具对比
- mysql 开发基础系列10 存储引擎 InnoDB 介绍
- kubernetes学习笔记之十一:kubernetes dashboard认证及分级授权
- CSS 选用字体
- 寒假生活第一天——Github初体验
- oracle 导出表
- Java 垃圾回收思维导图
- React 回忆录(一)为什么使用 React?
热门文章
- 左右分栏页面右侧无法出现滚动条bug
- 2011 luogu P1311 选择客栈
- Educational Codeforces Round 59 (Rated for Div. 2) (前四题)
- 洛谷 P4073 [WC2013]平面图
- 我的MySql掉队了
- 内存区--Java
- 前端面试绝对会考的JS问题!【已经开源】
- 条款23:宁一 non-member no-friend 替换member函数(prefer non-member non-friend functions to members functions)
- 计蒜客 Overlapping Rectangles (离散化)
- SQL 一次插入多条记录