Android 高德地图自定义Marker覆盖物

时间:2023-02-18 14:56:39

直接贴代码:

private void quernResCircle(LatLng latLng, String title, String address) {
View markerView = ViewGroup.inflate(LocationActivity.this, R.layout.marker_layout, null);
TextView content = markerView.findViewById(R.id.content);
content.setText("标题: " + title);
content.setBackgroundColor(Color.parseColor("#f7ff47"));
content.setTextColor(Color.parseColor("#111111"));
MarkerOptions icon = new MarkerOptions().position(latLng).title(title).snippet(address).icon(BitmapDescriptorFactory.fromView(markerView));
aMap.addMarker(icon);
CircleOptions circleOptions = new CircleOptions()
.center(latLng)
.radius(200)
.fillColor(Color.parseColor("#33f7ff47"))
.strokeColor(Color.parseColor("#f7ff47"))
.strokeWidth(2);
circleOptions.visible(true);
aMap.addCircle(circleOptions);
}

res下layout   marker_layout 资源

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_map_bubble"
android:padding="3dp"
android:text=""
android:textColor="#ffffff"
android:textSize="10sp" />

<ImageView
android:id="@+id/img_marker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/ic_station" />
</LinearLayout>

效果图

Android 高德地图自定义Marker覆盖物