关于高德地图添加Marker遇到的一些坑

最近有一个需求,是一个出行类的App,需要在乘客下单后在地图上显示乘客的头像以及司机的头像。
这时候就需要在地图上插上一个marker

ImageLoader.loadLisenter(mContext,headUrl,
imageView);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory
                .fromView(imageView1);
        LatLng latLng = new LatLng(lat,lon);

        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.setFlat(true);
        //设置覆盖物比例
        markerOptions.anchor(0.5f, 0.5f);
        markerOptions.icon(bitmapDescriptor);
        markerOptions.position(latLng);
        Marker marker = mAmap.addMarker(markerOptions);
        marker.setClickable(false);

在ImageLoader封装的这个工具类中,添加了一个接口,在外部调用接口回调,得到加载完成的Resouce。
这个Resouce是GlideDrawable的对象,可以调用getCurrent();方法,得到Drawable对象,从而进行imageView的资源设置

@Override
public void accomplish(Drawable drawable, ImageView imageView) {
        ImageView imageView1 = new ImageView(mContext);
        LinearLayout.LayoutParams pl = new LinearLayout.LayoutParams(90, 90);
        imageView.setLayoutParams(pl);
        imageView1.setImageDrawable(drawable);

        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory
                .fromView(imageView1);
        LatLng latLng = new LatLng(Double.parseDouble(mOrderDetailsBean.getUp_lat()),
                Double.parseDouble(mOrderDetailsBean.getUp_lon()));

        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.setFlat(true);
        //设置覆盖物比例
        markerOptions.anchor(0.5f, 0.5f);
        markerOptions.icon(bitmapDescriptor);
        markerOptions.position(latLng);
        Marker marker = mAmap.addMarker(markerOptions);
        marker.setClickable(false);
        }

拖了很久才开始写第一篇带了点技术的博客,刚开始写,发现自己并不知道怎么去描述,技术点也比较简单。希望能帮助到一些刚接触Android的小伙伴或者与我一样碰到这个问题的朋友吧。自己还需要多努力。写的不好或者不对的地方,欢迎大家提出来。

猜你喜欢

转载自blog.csdn.net/qq_25749749/article/details/79928279
今日推荐