zoukankan      html  css  js  c++  java
  • Android集成高德地图如何自定义marker

    高德地图自定义Marker
    高德地图默认的marker样式是这种

    一般的修改样式是通过icon接口来调整

    MarkerOptions markerOptions = new MarkerOptions()
                        .position(latlng)
                        .draggable(true)
                        .icon(BitmapDescriptorFactory.fromBitmap(bitmap));
    

    当遇到图片加文字的marker该如何自定义呢?如这样

    步骤:

    /**
         * 往地图上添加marker
         */
        public static void addMarkersToMap(Context context, AMap aMap, LatLng latlng, PointModel model) {
            if (aMap != null) {
                View view = View.inflate(context, R.layout.view_marker, null);
                TextView textView = (TextView) view.findViewById(R.id.tvQuality);
                ImageView imageView = (ImageView) view.findViewById(R.id.ivQuality);
                int aqi=Integer.parseInt(model.getAqi());
                if (aqi>0&&aqi<=100){
                    imageView.setImageResource(R.drawable.ic_quality_03);
                }else if(aqi>100&&aqi<=200){
                    imageView.setImageResource(R.drawable.ic_quality_02);
                }else if (aqi>200){
                    imageView.setImageResource(R.drawable.ic_quality_01);
                }else {
                    imageView.setImageResource(R.drawable.ic_quality_01);
                }
                textView.setText(model.getAqi());
                Bitmap bitmap = convertViewToBitmap(view);
                markerOptions = new MarkerOptions()
                        .position(latlng)
                        .draggable(true)
                        .icon(BitmapDescriptorFactory.fromBitmap(bitmap));
                marker = aMap.addMarker(markerOptions);
            }
        }
    

    自定义view,然后赋值,将view转化为bitmap即可:

     //view 转bitmap
        public static Bitmap convertViewToBitmap(View view) {
            view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
            view.buildDrawingCache();
            Bitmap bitmap = view.getDrawingCache();
            return bitmap;
        }
    

    原文:https://blog.csdn.net/qq_16131393/article/details/78252857

  • 相关阅读:
    html 复选框
    html 单选框
    C++创建类的对象(类的初始化)的方法
    C++创建类的对象(类的初始化)的方法
    C#基础实现URL Unicode编码,编码、解码相关整理
    C#基础实现URL Unicode编码,编码、解码相关整理
    js 发送http请求
    js 发送http请求
    C++的三种实例化对象方式
    C++的三种实例化对象方式
  • 原文地址:https://www.cnblogs.com/wzqnxd/p/10076188.html
Copyright © 2011-2022 走看看