百度POI

来源:互联网 发布:python爬虫有什么用 编辑:程序博客网 时间:2024/06/05 20:06
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);        }
0 0
原创粉丝点击