views:

311

answers:

4

Hello community,

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

A: 

Just removeAllAnnotations to your mapView and add the new ones, this will refresh the annotations on your map.

yonel
A: 

sorry do you have a code example, i don't know to use this?

Marco
+1  A: 

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.

samiq
+1  A: 

yonel, when removing them and adding them again, the image i have set for my annotations change and display the incorrect ones.

Alexj17