百度POI

public class MainActivity extends Activity {

    private MapView mMapView;
    private BaiduMap mBaiduMap;
    private PoiSearch mPoiSearch;
    private RoutePlanSearch mSearch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_main);
        mMapView = (MapView) findViewById(R.id.bmapView); 
        mBaiduMap = mMapView.getMap(); 
        mPoiSearch = PoiSearch.newInstance();
        mSearch = RoutePlanSearch.newInstance();
        Button but = (Button) findViewById(R.id.button);
        but.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mPoiSearch.searchInCity((new PoiCitySearchOption())  
                        .city("北京")  
                        .keyword("美食")  
                        .pageNum(10));
                PlanNode stNode = PlanNode.withCityNameAndPlaceName("北京", "龙泽");  
                PlanNode enNode = PlanNode.withCityNameAndPlaceName("北京", "西单");
                mSearch.drivingSearch((new DrivingRoutePlanOption())  
                        .from(stNode)  
                        .to(enNode));
            }
        });
        mPoiSearch.setOnGetPoiSearchResultListener(new OnGetPoiSearchResultListener() {

            @Override
            public void onGetPoiResult(PoiResult arg0) {
                // TODO Auto-generated method stub
                //获取POI检索结果
                 if (arg0.error == SearchResult.ERRORNO.NO_ERROR) {  
                        mBaiduMap.clear();  
                        //创建PoiOverlay  
                        PoiOverlay overlay = new PoiOverlay(mBaiduMap);  
                        //设置PoiOverlay数据  
                        overlay.setData(arg0);  
                        //添加PoiOverlay到地图中  
                        overlay.addToMap();  
                        overlay.zoomToSpan(); 
                        List<OverlayOptions> overlayOptions = overlay
                                .getOverlayOptions();

                        mBaiduMap.addOverlays(overlayOptions);
                        return;  
                    }  
            }

            @Override
            public void onGetPoiIndoorResult(PoiIndoorResult arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onGetPoiDetailResult(PoiDetailResult arg0) {
                // TODO Auto-generated method stub

            }
        });

        mSearch.setOnGetRoutePlanResultListener(new OnGetRoutePlanResultListener() {

            @Override
            public void onGetWalkingRouteResult(WalkingRouteResult arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onGetTransitRouteResult(TransitRouteResult arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onGetDrivingRouteResult(DrivingRouteResult arg0) {
                // TODO Auto-generated method stub
                 if (arg0.error == SearchResult.ERRORNO.NO_ERROR) {  
                        mBaiduMap.clear();  
                        //创建PoiOverlay  
                        DrivingRouteOverlay overlay = new DrivingRouteOverlay(mBaiduMap);  
                        //设置PoiOverlay数据  
                        overlay.setData(arg0.getRouteLines().get(0));
                        //添加PoiOverlay到地图中  
                        overlay.addToMap();  
                        overlay.zoomToSpan(); 
                        List<OverlayOptions> overlayOptions = overlay
                                .getOverlayOptions();

                        mBaiduMap.addOverlays(overlayOptions);
                        return;  
                    }  
            }

            @Override
            public void onGetBikingRouteResult(BikingRouteResult arg0) {
                // TODO Auto-generated method stub

            }
        });

//        goujina2();
//        goud();
    }
     @Override  
        protected void onDestroy() {  
            super.onDestroy();  
            //在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理  
            mMapView.onDestroy();  
        }  
        @Override  
        protected void onResume() {  
            super.onResume();  
            //在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理  
            mMapView.onResume();  
            }  
        @Override  
        protected void onPause() {  
            super.onPause();  
            //在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理  
            mMapView.onPause();  
            }  


        public void goujina2(){
            // 构造折线点坐标
            List<LatLng> points = new ArrayList<LatLng>();
            points.add(new LatLng(39.940,116.390));
            points.add(new LatLng(39.940,116.500));
            points.add(new LatLng(39.895,116.410));
            points.add(new LatLng(39.970,116.445));
            points.add(new LatLng(39.895,116.480));
            points.add(new LatLng(39.940,116.390));

            //构建分段颜色索引数组
            List<Integer> colors = new ArrayList<Integer>();
            colors.add(Integer.valueOf(Color.BLUE));
            colors.add(Integer.valueOf(Color.RED));
            colors.add(Integer.valueOf(Color.YELLOW));
            colors.add(Integer.valueOf(Color.GREEN));
            colors.add(Integer.valueOf(Color.BLACK));

            OverlayOptions ooPolyline = new PolylineOptions().width(10)
                    .colorsValues(colors).points(points);
//          添加在地图中
            Polyline  mPolyline = (Polyline) mBaiduMap.addOverlay(ooPolyline);
        }


        public void goud(){
            //定义文字所显示的坐标点  
            LatLng llText = new LatLng(39.975, 116.445);  
            //构建文字Option对象,用于在地图上添加文字  
            OverlayOptions textOption = new TextOptions()  
                .bgColor(0xAAFFFF00)  
                .fontSize(24)  
                .fontColor(0xFFFF00FF)  
                .text("五角星")  
                .position(llText);  
            //在地图上添加该文字对象并显示  
            mBaiduMap.addOverlay(textOption);

        }
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值