Display custom View method on Gaode map

There is a requirement in the project to display the person's avatar on the map to display the user's location. There are many such map applications, and the most common one is the real-time location sharing effect of WeChat.
WeChat real-time location sharing
The demo provided by Gaode only draws icons on the map, and does not explain how to achieve this effect. Here is the implementation method:
1. Custom layout file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null">
    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_centerInParent="true"
        android:adjustViewBounds="true"
        android:background="@null"
        android:src="@drawable/ic_bubble" />

    <com.away.mother.view.CircularImage
        android:id="@+id/badge"
        android:layout_width="52dp"
        android:layout_height="52dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:background="@null"                 android:src="@drawable/friendactivity_personalportrait_default" />
</RelativeLayout>

A custom control is used here to display a circular avatar, and you can choose different controls according to the actual application.
2. Code implementation:

public View getBubble(String userhead) {
View view = this.getLayoutInflater().inflate(R.layout.layout_bubble,
null);
ImageView iv_user = (ImageView) view.findViewById(R.id.badge);

String image = userhead;
Bitmap bm = imageLoader.getBitmapFromMemoryCache(image);
if (bm != null) {
iv_user.setImageBitmap(bm);
}
return view;
}

/**
* 绘制系统默认的1种marker背景图片
*/
public void drawMarkers(LatLng latlng, String loc, String userhead) {
//获取自定义View
View view = getBubble(true, loc, userhead);

//创建Marker对象
Marker marker = aMap.addMarker(new MarkerOptions().position(latlng)
.icon(BitmapDescriptorFactory.fromView(view)).draggable(true));
int dir = (int) (Math.random() * 360);
Marker markerloc = null;
//绘制方向小蓝点
markerloc = aMap.addMarker(new MarkerOptions()
.position(latlng)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_loc)).draggable(true)
.anchor(0.5f, 0.5f));
markerloc.setRotateAngle(dir);
changeCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition(
latlng, 18, 30, 0)), this);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325865048&siteId=291194637