美文网首页
腾讯地图

腾讯地图

作者: 橙果子 | 来源:发表于2019-06-26 17:15 被阅读0次

    集成参考腾讯地图API官方文档 https://lbs.qq.com/index.html
    腾讯地图参考手册: https://lbs.qq.com/AndroidDocs/doc_3d/index.html

    腾讯地图定位,添加图层等都可以参考官方的demo
    记录部分demo没有的方法

    1.设置不要定位的蓝色圆圈

    TencentMap tencentMap = mapview.getMap();
     MyLocationStyle myLocationStyle = new MyLocationStyle();
     myLocationStyle.strokeColor(Color.argb(0, 0, 0, 0));
     myLocationStyle.fillColor(Color.argb(0, 0, 0, 0));
     tencentMap.setMyLocationStyle(myLocationStyle);
    

    2.地图移动到任意一个位置,或回到我的位置,带动画

     LatLng latLng = new LatLng(lat, lont);
    //这个方法没有移动的动画, 是一下回到当前位置
     tencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16));
    //这个方法有移动的动画效果
     tencentMap.animateCamera(CameraUpdateFactory.newCameraPosition
                            (new CameraPosition(latLng, 16, 0, 0)), 500, null);
    

    animateCamera官网的方法说明

    #

    3.自定义View添加标注,自定义样式添加图层,并为Marker添加点击事件, 设置Marker的时候设置一个tag,方便获取id

     /**
      * 自定义标注样式
      */
    public View getMarkerCountView(String names, int icon) {
            View view = this.getLayoutInflater().inflate(R.layout.around_marker_items, null);
            ImageView imageView = view.findViewById(R.id.portratir);
            imageView.setImageResource(icon);
            TextView txt_count = view.findViewById(R.id.nameTv);
            txt_count.setText(names);
            return view;
        }
    
     View view = getMarkerCountView("标题", R.mipmap.tupian);
    //显示资源图片的方法
    //icon(BitmapDescriptorFactory.fromBitmap( BitmapFactory.decodeResource(getResources(), R.mipmap.liwu))).
    //设置一个tag,当你需要点击Marker的时候,可以获取到相应的id
    int tag=id;
     Marker zhouweimarker = tencentMap.addMarker(new MarkerOptions()
                            .tag(tags)
                            .position(new LatLng(lat, lnt))
                            .icon(BitmapDescriptorFactory.fromView(view))
                            .anchor(0.1f, 0.1f));
    //标注的点击事件设置
    tencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {
                    //这个tag就是我们在设置图层的时候设置的ID
                    int id= marker.getTag();
    
                    return false;
                }
            });
    

    4.加减缩放地图

    //把地图放大一级
     tencentMap.animateCamera(CameraUpdateFactory.zoomIn());
    //把地图缩小一级
     tencentMap.animateCamera(CameraUpdateFactory.zoomOut());
    
    image.png

    相关文章

      网友评论

          本文标题:腾讯地图

          本文链接:https://www.haomeiwen.com/subject/zsgccctx.html