I am working on Android application which makes use of Google Maps and Google Maps Android API Utility Library. By making use of the utility library I got the clustered markers. But I want to show circle around the marker, when markers become visible. Following is the code I am using to add clustered markers:
public class ClusterMarkersFragment {
public GoogleMap map;
private ClusterManager<MarkerItem> fenceClusterManager;
public static ClusterMarkersFragment newInstance () {
ClusterMarkersFragment clusterMarkersFragment = new
ClusterMarkersFragment();
return clusterMarkersFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate( R.layout.fragment_cluster_marker_map,
container, false );
map = ((SupportMapFragment) getChildFragmentManager()
.findFragmentById( R.id.view_map )).getMap();
map.setMyLocationEnabled(false);
fenceClusterManager = new ClusterManager<MarkerItem>(getActivity(), map);
map.setOnCameraChangeListener(fenceClusterManager);
addClusterItems(getListofLatLngPairs());
return view;
}
private List< LatLngPair > getListofLatLngPairs () {
// returns the list from database
}
private void addClusterItems(List<LatLngPair> latLngPairs) {
for (LatLngPair latLngPair : latLngPairs) {
MarkerItem markerItem = new MarkerItem(latLngPair.lat, latLngPair.lng, (int) latLngPair);
fenceClusterManager.addItem(markerItem);
}
}
}
Following are the screenshots
Try this:
private void addcircleAroundMarker() {
GoogleMap mapView;
// circle settings
int radiusM = RADIUS OF CIRCLE;
double latitude = CENTER LATITUDE;
double longitude = CENTER LONGITUDE;
LatLng latLng = new LatLng(latitude,longitude);
// draw circle
// diameter
int d = 500;
Bitmap bm = Bitmap.createBitmap(d, d, Config.ARGB_8888);
Canvas c = new Canvas(bm);
Paint p = new Paint();
p.setColor(getResources().getColor(R.color.green));
c.drawCircle(d/2, d/2, d/2, p);
BitmapDescriptor bmD = BitmapDescriptorFactory.fromBitmap(bm);
mapView.addGroundOverlay(new GroundOverlayOptions().
image(bmD).
position(latLng,radiusM*2,radiusM*2).
transparency(0.4f));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.