关于高德地图添加Marker遇到的一些坑你知道吗
【摘要】
本文转载自https://blog.csdn.net/m0_37295672/article/details/77851580
最近有一个需求,是一个出行类的App,需要在乘客下单后在地图上显示乘客的头像以及司机的头像。 这时候就需要在地图上插上一个marker
ImageLoader.loadLisenter(mContext,h...
本文转载自https://blog.csdn.net/m0_37295672/article/details/77851580
最近有一个需求,是一个出行类的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的小伙伴或者与我一样碰到这个问题的朋友吧。自己还需要多努力。写的不好或者不对的地方,欢迎大家提出来。
文章来源: chengsy.blog.csdn.net,作者:程思扬,版权归原作者所有,如需转载,请联系作者。
原文链接:chengsy.blog.csdn.net/article/details/79928279
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)