开发者

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];
 kundenPo开发者_运维知识库ints = [[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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜