My client / has asked me to set the opacity (alpha) for various different Placemarks found on the MKMapView depending on what the date was.
For the oldest half of the place marks, he would like the opacity to be set to 0.5.
I can do this by working out the index of the place mark and checking to see whether it is in the last half of the array.
int indexOfPlacemark = [fixes indexOfObject:fix]; //fixes is the array of Placemarks (named fix).
if (index <= [fixes count] / 2) {
[annotationView setAlpha:0.5];
}
else {
// do something with fix.date to work out the opacity.
// an example of the date is Sun, May 15, 2011 - 12:00:44
}
But then he wants me to raise the opacity for every other place mark depending on its date. I.e the latest date will have an opacity of 1.0, and the oldest date in the first half of the array will be ~0.5.
What I would like to know is how I can work out the opacity depending on its date.
First you should get the time elapsed between the oldest date and the latest date:
Then, for each of the placemarks, you should do the following:
This way, with the older dates, timeElapsed would be closer to 0, resulting in alphas closer to 0.5. And with newer dates, timeElapsed would be closer to maxTimeElapsed, making alpha closer to 1 (and alpha = 1 with the latest date).