先看下效果圖吧:
這個需要自定義布局來實作如果僅僅隻靠Marker本身實作不了隻能實作(如下圖)
第一步寫個XML:
<?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/tv_endphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_dialog"
android:textColor="#000000"
android:text="132111111111"/>
<ImageView
android:id="@+id/img_marker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/marker_passengersitestart_blue"/>
</LinearLayout>
第二步繪制Marker:
View markerView = ViewGroup.inflate(InterCityDuringActivity.this, R.layout.map_markerview, null);
TextView tv_endphone = markerView.findViewById(R.id.tv_endphone);
ImageView img_marker = markerView.findViewById(R.id.img_marker);
LatLng latLng = new LatLng(“緯度”, “經度”);
tempList.add(latLng);
tv_endphone.setText("尾号" + endPhone);
MarkerOptions icon = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromView(markerView));
aMap.addMarker(icon);
//參數依次是:視角調整區域的中心點坐标、希望調整到的縮放級别、俯仰角0°~45°(垂直與地圖時為0)、偏航角 0~360° (正北方為0)
CameraUpdate mCameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(new LatLng(lat, lon), 18, 30, 0));
aMap.moveCamera(mCameraUpdate);
這樣就完成繪制了。
希望對大家有所幫助!!