Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MACloop

macrumors 6502
Original poster
May 18, 2009
393
0
Germany
How is it possible to remove all annotation on a mapview except for the current userLocation?
I tried this:

Code:
NSMutableArray *arr = [NSMutableArray alloc] initWithArray[startMap annotations]];

  for (MKAnnotation *a in [mapView annotations]) {
    if(a != mapView.userLocation) {
      [arr addObject:a];
    }
  }
[mapView removeAnnotations:arr];


But it does not work :-( Is there a way to detect/compare the current user location?
 
have you tried:
Code:
if(a.location != mapView.userLocation)

also, depending on how many annotations you have or if that fits well with your code, rather than cycling thru all your annotations just to find the ones that aren't the user location, you could simply remove them all first and then add the user location afterwards.
 
have you tried:
Code:
if(a.location != mapView.userLocation)

also, depending on how many annotations you have or if that fits well with your code, rather than cycling thru all your annotations just to find the user location, you could simply remove them all first and then add the user location afterwards.

That will not work I think. MKAnnotation has no property named location and mapView.userLocation is a MKUserLocation which inherites from MKAnnotation or am I wrong???? I just want to compare the annotation taken from the mapView with the users current location and delete all other annotations.
 
in my annotation object subclass i can get the annotations latitude and logitude thru CLLocationCoordinate2D.

Code:
- (CLLocationCoordinate2D)coordinate
	{
	CLLocationCoordinate2D theCoordinate = {self.latitude, self.longitude};
	return theCoordinate;
	}

so you could do something like

Code:
if (a.coordinate != userLocation)

sorry, i'm mostly thinking out loud here, and it's been a while since i used MKMapKit.
 
No problem! I am glad for any advice and will look at your example and how that could fit into my solution.
Thanks!
 
have you tried:
Code:
if(a.location != mapView.userLocation)

also, depending on how many annotations you have or if that fits well with your code, rather than cycling thru all your annotations just to find the ones that aren't the user location, you could simply remove them all first and then add the user location afterwards.

I have tried that to first remove all and then add the userLocation again. That did not work... :-(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.