Reputation: 2443
In an app I limited total number of markers to 50, after which the user should delete markers to be able to pin more. Now I want to disable users from pinning large number of markers in a small time periods, I want to allow him to pin only 2 per day.
Code so far:
private GoogleMap mMap;
Marker marker; // Marker
int markerCount = 0; // Marker counter
//Add marker on long click
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
int iMax = 50; // Max number of markers
@Override
public void onMapLongClick(LatLng arg0) {
if (markerCount < iMax) {
// start SendMessageActivity need to add marker to message activity
startActivity(new Intent(MapsActivity.this, SendMessageActivity.class));
markerCount = markerCount + 1;
marker = mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.custom_marker))
.position(
new LatLng(arg0.latitude,
arg0.longitude))
.visible(true));
} else {
Toast.makeText(getApplicationContext(), "Only " + iMax + " markers allowed at the same time",
Toast.LENGTH_LONG).show();
}
}
});
Upvotes: 1
Views: 72
Reputation: 801
I suggest keeping a count in SharedPreferences, which is reset by an Alarm scheduled every day at 12:00 AM.
Upvotes: 2