百度地图开发—基础的用法

来源:互联网 发布:数据库系统的作用 编辑:程序博客网 时间:2024/06/05 11:33

百度地图一些常用的方法和代码:


1.百度地图热力图(http://map.baidu.com/heatmap/index/index )2.百度坐标拾取(http://api.map.baidu.com/lbsapi/getpoint/index.html )3.百度迁徙(http://qianxi.baidu.com/ )4.商户免费标注(http://biaozhu.baidu.com/?from=maptop#/ 可标注自己的公司在地图上的位置)

图层分类:


底图

卫星图(卫星地图是卫星拍摄的真实的地理面貌,所以卫星地图可用来检测地面的信息,你可以了解到地理位置,地形等。)

交通图


1、基础底图(包括底图、底图道路、卫星图等);2、地形图图层(GroundOverlay);3、热力图图层(HeatMap);4、实时路况图图层(BaiduMap.setTrafficEnabled(true););5、百度城市热力图(BaiduMap.setBaiduHeatMapEnabled(true););6、底图标注(指的是底图上面自带的那些POI元素);7、几何图形图层(点、折线、弧线、圆、多边形);8、标注图层(Marker),文字绘制图层(Text);9、指南针图层(当地图发生旋转和视角变化时,默认出现在左上角的指南针);10、定位图层(BaiduMap.setMyLocationEnabled(true););11、弹出窗图层(InfoWindow);12、自定义View(MapView.addView(View));

1.本地覆盖物:


本地覆盖物的抽象基类:OverlayOptions圆形覆盖物: CircleOptions文字覆盖物: TextOptions圆点覆盖物:DotOptionsground 覆盖物:GroundOverlayOptions多边形覆盖物:PolygonOptions折线覆盖物:PolylineOptions弧线覆盖物:ArcOptions

1.旋转30度


getmapStatus = map.getMapStatus();               float rotate = getmapStatus.rotate + 30;                MapStatus mapStatus = new MapStatus                .Builder()                .rotate(rotate)                .build();                mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus);

2.倾斜50度


 getmapStatus = map.getMapStatus();                float overlook = getmapStatus.overlook - 5;                MapStatus mapStatus1 = new MapStatus                .Builder()                .overlook(overlook)                .build();       mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus1);

3.显示普通地图


             MapStatusUpdate mapStatusUpdate = null;            map.setMapType(BaiduMap.MAP_TYPE_NORMAL);            map.setTrafficEnabled(false);

4.显示卫星地图


 map.setMapType(BaiduMap.MAP_TYPE_SATELLITE);                map.setTrafficEnabled(false);

5.显示交通地图


            map.setTrafficEnabled(true);

6.半径的覆盖


    CircleOptions circleOptions = new CircleOptions();    //圆心    circleOptions.center(latLng)            .radius(100) //半径            .stroke(new Stroke(20, 0x55FF00))   //线条宽度            .fillColor(0x5500FF00);   //圆的填充颜色    map.addOverlay(circleOptions);

7.文本的覆盖


            TextOptions textOptions = new TextOptions();            textOptions.position(latLng)                    .text("严丹枫")                    .fontSize(20)                    .fontColor(0xff000000)                    .bgColor(0x55ff0000)                    .rotate(30);            map.addOverlay(textOptions);

8.标志物覆盖(重点)


  BaiduMap.OnMarkerClickListener onMarkerClickListener = new BaiduMap.OnMarkerClickListener() {                    private TextView tv_title;                    @Override                    public boolean onMarkerClick(Marker marker) {                        if (pop == null) {                            //显示一个泡泡                            pop = View.inflate(getApplicationContext(), R.layout.pop, null);                            tv_title = pop.findViewById(R.id.tv_title);                            mMapView.addView(pop, getMapViewLayoutParams(marker.getPosition()));                        } else {                            mMapView.updateViewLayout(pop, getMapViewLayoutParams(marker.getPosition()));                        }                        tv_title.setText(marker.getTitle());                        return true;                    }                };                map.setOnMarkerClickListener(onMarkerClickListener);                map.setOnMarkerDragListener(onMarkerDragListener);                onMarkerDragListener = new BaiduMap.OnMarkerDragListener() {                    @Override                    public void onMarkerDrag(Marker marker) {                        mMapView.updateViewLayout(pop, getMapViewLayoutParams(marker.getPosition()));                    }                    @Override                    public void onMarkerDragEnd(Marker marker) {                        mMapView.updateViewLayout(pop, getMapViewLayoutParams(marker.getPosition()));                    }                    @Override                    public void onMarkerDragStart(Marker marker) {                        mMapView.updateViewLayout(pop, getMapViewLayoutParams(marker.getPosition()));                    }                };

 /*    *    * chua创建一个布局参数    * */    @NonNull    private MapViewLayoutParams getMapViewLayoutParams(LatLng position) {        MapViewLayoutParams.Builder builder = new MapViewLayoutParams.Builder();        builder.layoutMode(MapViewLayoutParams.ELayoutMode.mapMode);        //指定坐标为经纬度        builder.position(position);//设置坐标位置        builder.yOffset(-25);        return builder.build();    }

pop.xml


<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:background="@drawable/popupmap"    android:gravity="center_vertical">    <ImageView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginBottom="2dip"        android:src="@drawable/round" />    <TextView        android:id="@+id/tv_title"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:ellipsize="end"        android:text="标题"        android:textSize="20sp" />    <ImageView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/roads" /></LinearLayout>

9.搜索覆盖物


    搜索覆盖物抽象类: OverlayManager    兴趣点覆盖物:PoiOverlay    驾车路线覆盖物:DrivingRouteOverlay    步行路线覆盖物:WalkingRouteOverlay    换乘路线覆盖物:TransitOverlay

/**     * 城市内搜索,直接根据输入框的内容去实现Poi搜索.     */    private void citySearch(int page) {        // 设置检索参数        PoiCitySearchOption citySearchOption = new PoiCitySearchOption();        citySearchOption.city(editCityEt.getText().toString());// 城市        citySearchOption.keyword(editSearchKeyEt.getText().toString());// 关键字        citySearchOption.pageCapacity(15);// 默认每页10条        citySearchOption.pageNum(page);// 分页编号        // 为PoiSearch设置搜索方式.        poiSearch.searchInCity(citySearchOption);    }    /**     * 范围检索,范围搜索需要制定坐标.以矩形的方式进行范围搜索.     */    private void boundSearch(int page) {        PoiBoundSearchOption boundSearchOption = new PoiBoundSearchOption();        LatLng southwest = new LatLng(latitude - 0.01, longitude - 0.012);// 西南        LatLng northeast = new LatLng(latitude + 0.01, longitude + 0.012);// 东北        LatLngBounds bounds = new LatLngBounds.Builder().include(southwest)                .include(northeast).build();// 得到一个地理范围对象        boundSearchOption.bound(bounds);// 设置poi检索范围        boundSearchOption.keyword(editSearchKeyEt.getText().toString());// 检索关键字        boundSearchOption.pageNum(page);        poiSearch.searchInBound(boundSearchOption);// 发起poi范围检索请求    }    /**     * 附近检索,范围搜索需要指定圆心.以圆形的方式进行搜索.     */    private void nearbySearch(int page) {        PoiNearbySearchOption nearbySearchOption = new PoiNearbySearchOption();        nearbySearchOption.location(new LatLng(latitude, longitude));        nearbySearchOption.keyword(editSearchKeyEt.getText().toString());        nearbySearchOption.radius(1000);// 检索半径,单位是米        nearbySearchOption.pageNum(page);        poiSearch.searchNearby(nearbySearchOption);// 发起附近检索请求    }

OnGetPoiSearchResultListener poiSearchListener = new OnGetPoiSearchResultListener() {        // 获取poiResult        @Override        public void onGetPoiResult(PoiResult poiResult) {            if (poiResult.error == SearchResult.ERRORNO.NO_ERROR) {                bdMap.clear();                MyPoiOverlay poiOverlay = new MyPoiOverlay(bdMap);  //实例化poiOverlay对象.                poiOverlay.setData(poiResult); //设置poiOverlay数据.                bdMap.setOnMarkerClickListener(poiOverlay);//当标志物被点击时监听设置.                poiOverlay.addToMap();//将所有的poi添加到Map上.                poiOverlay.zoomToSpan();                totalPage = poiResult.getTotalPageNum();                Toast.makeText(                        PoiSearchActivity.this,                        "总共查到" + poiResult.getTotalPoiNum() + "个兴趣点,分为"                                + totalPage + "页", Toast.LENGTH_SHORT).show();            }        }        // 当点击覆盖物的时候,查询详细的数据信息,作为回调返回数据信息        @Override        public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {        }    };

阅读全文
0 0
原创粉丝点击