地图集成代码就省略,直接整主要代码:
for (int i = 0; i < marketList.size(); i++) {
aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(marketList.get(i).getLatitude(),//设置纬度
marketList.get(i).getLongitude())));
marker = aMap.addMarker(new MarkerOptions().anchor(1.5f, 3.5f)
.position(new LatLng(marketList.get(i).getLatitude(),//设置纬度
marketList.get(i).getLongitude()))//设置经度
.title(marketList.get(i).getTitle())//设置标题
.snippet(marketList.get(i).getContent())//设置内容
// .setFlat(true) // 将Marker设置为贴地显示,可以双指下拉地图查看效果
.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
.decodeResource(mContext.getResources(), R.mipmap.poi_marker_pressed)))
.draggable(true) //设置Marker可拖动
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_launcher)));
}
marker.showInfoWindow();
多个infowindow算是投机取巧 没有找到合适的方法
for (int i = 0; i < marketList.size(); i++) {
final LocationMarketBean locationMarketBean = marketList.get(i);
markerOption = new MarkerOptions().icon(BitmapDescriptorFactory
.fromView(getBitmapView(LocationMarkerInfoWindowsActivity.this, locationMarketBean)));
markerOption.position(new LatLng(locationMarketBean.getLatitude(), locationMarketBean.getLongitude()));
markerOption.setFlat(true);
markerOption.draggable(false);
marker = aMap.addMarker(markerOption);
markerOptionlst.add(markerOption);
}
markersOnListen = aMap.addMarkers(markerOptionlst, true);
aMap.setOnMarkerClickListener(marker -> {
for (int i = 0; i < markersOnListen.size(); i++) {
if (marker.equals(markersOnListen.get(i))) {
Toast.makeText(LocationMarkerInfoWindowsActivity.this, marketList.get(i).getTitle(), Toast.LENGTH_SHORT).show();
}
}
return false;
});
技术有限,只提供思路,不喜勿喷,忘各位大佬手下留情。