Search code examples
iphonemkmapviewcllocationmanagermkpinannotationview

Refresh my mapView


i have a mapView with pins on it, and the following code for CLLocation and getDistance between me and another points on the map:

    - (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{

 Koordinate *kunde = [[Koordinate alloc] init];
 kundenPoints = [[NSMutableArray array] retain];

 for(int i = 0; i<[eventPoints count]; i++){
  kunde = [eventPoints objectAtIndex:i];
  CLLocation *userLoc = [[CLLocation alloc] initWithLatitude:kunde.latitude longitude:kunde.longtitude];
  double distance = [newLocation getDistanceFrom:userLoc] / 1000;
  if(distance <= 100){
   [kundenPoints addObject:kunde];
  }else {
  }
 }
 [mapView addAnnotations:kundenPoints];
}

but how can i implement a method that refreshes the map when i tab on a button? that i always get the pins around me when i want. the button is not the problem, only the refresh!

i hope someone could help me??

best regards Marco


Solution

  • as far as I know there is no such a thing as removeAllAnnotations, at least not in iOS4 SDK... although you can quickly fix it using

    NSArray *ants = [mapView_ annotations];
    [mapView_ removeAnnotations:ants];
    

    same goes for overlays

    NSArray *ants = [mapView_ overlays];
    [mapView_ removeOverlays:ants];
    

    so far is the best way I've found to do it.