百度地图之短串分享(二)
er;
import com.baidu.mapapi.search.MKShareUrlResult;
import com.baidu.mapapi.search.MKSuggestionResult;
import com.baidu.mapapi.search.MKTransitRouteResult;
import com.baidu.mapapi.search.MKWalkingRouteResult;
import com.baidu.platform.comapi.basestruct.GeoPoint;
/**
* 演示poi搜索功能
*/
public class ShareDemoActivity extends Activity {
private MapView mMapView = null;
private MKSearch mSearch = null; // 搜索模块,也可去掉地图模块独立使用
// 保存搜索结果地址
private String currentAddr = null;
// 搜索城市
private String mCity = "北京";
// 搜索关键字
private String searchKey = "餐馆";
// 反地理编译点坐标
private GeoPoint mPoint = new GeoPoint((int) (40.056878 * 1E6),
(int) (116.308141 * 1E6));
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DemoApplication app = (DemoApplication) this.getApplication();
if (app.mBMapManager == null) {
app.mBMapManager = new BMapManager(this);
app.mBMapManager.init(DemoApplication.strKey,
new DemoApplication.MyGeneralListener());
}
setContentView(R.layout.activity_share_demo_activity);
mMapView = (MapView) findViewById(R.id.bmapView);
mMapView.getController().enableClick(true);
mMapView.getController().setZoom(12);
// 初始化搜索模块,注册搜索事件监听
mSearch = new MKSearch();
mSearch.init(app.mBMapManager, new MKSearchListener() {
@Override
public void onGetPoiDetailSearchResult(int type, int error) {
}
/**
* 在此处理poi搜索结果 , 用poioverlay 显示
*/
public void onGetPoiResult(MKPoiResult res, int type, int error) {
// 错误号可参考MKEvent中的定义
if (error != 0 || res == null) {
Toast.makeText(ShareDemoActivity.this, "抱歉,未找到结果",
Toast.LENGTH_LONG).show();
return;
}
// 将地图移动到第一个POI中心点
if (res.getCurrentNumPois() > 0) {
// 将poi结果显示到地图上
PoiShareOverlay poiOverlay = new PoiShareOverlay(
ShareDemoActivity.this, mMapView);
poiOverlay.setData(res.getAllPoi());
mMapView.getOverlays().clear();
mMapView.getOverlays().add(poiOverlay);
mMapView.refresh();
// 当ePoiType为2(公交线路)或4(地铁线路)时, poi坐标为空
for (MKPoiInfo info : res.getAllPoi()) {
if (info.pt != null) {
mMapView.getController().animateTo(info.pt);
break;
}
}
}
}
public void onGetDrivingRouteResult(MKDrivingRouteResult res,
int error) {
}
public void onGetTransitRouteResult(MKTransitRouteResult res,
int error) {
}
public void onGetWalkingRouteResult(MKWalkingRouteResult res,
int error) {
}
/**
* 在此处理反地理编结果
*/
public void onGetAddrResult(MKAddrInfo res, int error) {
// 错误号可参考MKEvent中的定义