BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.qidian));
final Marker marker = aMap.addMarker(new MarkerOptions().position(latLng).icon(bitmapDescriptor));
mapView = (MapView) findViewById(R.id.map);
//在activity执行onCreate时执行mMapView.onCreate(savedInstanceState),实现地图生命周期管理
mapView.onCreate(savedInstanceState);
if (aMap == null) {
Log.i("lgq","sssssfa====aMap == null");
aMap = mapView.getMap();
//设置显示定位按钮 并且可以点击
UiSettings settings = aMap.getUiSettings();
aMap.setLocationSource(this);//设置了定位的监听
// 是否显示定位按钮
settings.setMyLocationButtonEnabled(true);
aMap.setMyLocationEnabled(true);//显示定位层并且可以触发定位,默认是flase
aMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Log.i("lgq","dianjiddd===="+marker.getPeriod());//获取markerID
bottomli.setVisibility(View.VISIBLE);
bottomte.setText("地址是:"+marker.getPeriod());
return false;
}
});
添加多个Marker
setMarker("大象网吧",23.025845,113.752532,1);
setMarker("小猴网吧",23.025845,113.772532,2);
setMarker("大英超网吧",23.024845,113.782532,3);
setMarker("京山市场网吧",23.086634,113.849915,4);
setMarker("东城亿嘉网咖",23.036034,113.816161,5);
public void setMarker(String barname,double wd,double jd,int mid){
LayoutInflater mInflater = LayoutInflater.from(this);
View view = mInflater.inflate(R.layout.zdyview, null);
TextView textView = view.findViewById(R.id.tete);
textView.setText(barname);
Bitmap bitmap =convertViewToBitmap(view);
//绘制marker
Marker marker2 = aMap.addMarker(new MarkerOptions()
.position(new LatLng(wd,jd)).period(mid)//添加markerID
.icon(BitmapDescriptorFactory.fromBitmap(bitmap))
.draggable(false));
}
public static Bitmap convertViewToBitmap(View view) {
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
return bitmap;
}
zdyview文件