package bw.com.bw_day10.demo03;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiCitySearchOption;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiIndoorResult;
import com.baidu.mapapi.search.poi.PoiResult;
import com.baidu.mapapi.search.poi.PoiSearch;
import bw.com.bw_day10.R;
import bw.com.bw_day10.overlayutil.PoiOverlay;
public class PoiActivity extends AppCompatActivity {
private MapView mMapView;
private BaiduMap mBaiduMap;//地图管理器对象
private PoiSearch mPoiSearch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO 初始化地图
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_poi);
mMapView = (MapView) findViewById(R.id.map_view_id);
mBaiduMap = mMapView.getMap();
//TODO 1 , 创建POI检索实例
mPoiSearch = PoiSearch.newInstance();
//TODO 2 , 创建POI检索监听者;
OnGetPoiSearchResultListener poiListener = new OnGetPoiSearchResultListener(){
public void onGetPoiResult(PoiResult result){
Log.e("Tag","error --- " + result.error);
//TODO 6, 获取POI检索结果
if (result != null && result.error == SearchResult.ERRORNO.NO_ERROR)
{
// TODO: 6.1 清除百度地图
// mBaiduMap.clear();
// TODO: 6.2 构建图层 -- 需要从刚刚下载的zip 包中, 提取 src/main/java --- overlayutil
PoiOverlay poiOverlay = new PoiOverlay(mBaiduMap);
mBaiduMap.setOnMarkerClickListener(poiOverlay);
//TODO: 6.3 设置poi 的数据
poiOverlay.setData(result);
//TODO: 6.4 添加PoiOverlay 到地图中
poiOverlay.addToMap();//将图层显示出去
poiOverlay.zoomToSpan();//将地图缩放到合适的比例展示
}
}
public void onGetPoiDetailResult(PoiDetailResult result){
//获取Place详情页检索结果
}
@Override
public void onGetPoiIndoorResult(PoiIndoorResult poiIndoorResult) {
// 获取室内检索的结果
}
};
//TODO 3, 设置POI检索监听者;
mPoiSearch.setOnGetPoiSearchResultListener(poiListener);
onClick();//模拟点击事件监听器
}
public void onClick()
{
//TODO 4, 发起检索请求;
mPoiSearch.searchInCity((new PoiCitySearchOption())
.city("北京")//城市
.keyword("旅游景点")//所示的关键字
.pageNum(10));//显示的条目
//TODO 5, 释放POI检索实例;
mPoiSearch.destroy();
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mMapView.onPause();
}
}
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiCitySearchOption;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiIndoorResult;
import com.baidu.mapapi.search.poi.PoiResult;
import com.baidu.mapapi.search.poi.PoiSearch;
import bw.com.bw_day10.R;
import bw.com.bw_day10.overlayutil.PoiOverlay;
public class PoiActivity extends AppCompatActivity {
private MapView mMapView;
private BaiduMap mBaiduMap;//地图管理器对象
private PoiSearch mPoiSearch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO 初始化地图
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_poi);
mMapView = (MapView) findViewById(R.id.map_view_id);
mBaiduMap = mMapView.getMap();
//TODO 1 , 创建POI检索实例
mPoiSearch = PoiSearch.newInstance();
//TODO 2 , 创建POI检索监听者;
OnGetPoiSearchResultListener poiListener = new OnGetPoiSearchResultListener(){
public void onGetPoiResult(PoiResult result){
Log.e("Tag","error --- " + result.error);
//TODO 6, 获取POI检索结果
if (result != null && result.error == SearchResult.ERRORNO.NO_ERROR)
{
// TODO: 6.1 清除百度地图
// mBaiduMap.clear();
// TODO: 6.2 构建图层 -- 需要从刚刚下载的zip 包中, 提取 src/main/java --- overlayutil
PoiOverlay poiOverlay = new PoiOverlay(mBaiduMap);
mBaiduMap.setOnMarkerClickListener(poiOverlay);
//TODO: 6.3 设置poi 的数据
poiOverlay.setData(result);
//TODO: 6.4 添加PoiOverlay 到地图中
poiOverlay.addToMap();//将图层显示出去
poiOverlay.zoomToSpan();//将地图缩放到合适的比例展示
}
}
public void onGetPoiDetailResult(PoiDetailResult result){
//获取Place详情页检索结果
}
@Override
public void onGetPoiIndoorResult(PoiIndoorResult poiIndoorResult) {
// 获取室内检索的结果
}
};
//TODO 3, 设置POI检索监听者;
mPoiSearch.setOnGetPoiSearchResultListener(poiListener);
onClick();//模拟点击事件监听器
}
public void onClick()
{
//TODO 4, 发起检索请求;
mPoiSearch.searchInCity((new PoiCitySearchOption())
.city("北京")//城市
.keyword("旅游景点")//所示的关键字
.pageNum(10));//显示的条目
//TODO 5, 释放POI检索实例;
mPoiSearch.destroy();
}
@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
mMapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mMapView.onPause();
}
}