IPhone MapKit - Update Coordinates and Annotation Map

I use this tutorial to integrate MapKit into my application: http://iphonebcit.wordpress.com/iphone-map-kit-tutorial/

CLLocationCoordinate2D coordinate;
coordinate.latitude = 49.2802;
coordinate.longitude = -123.1182;

NSUInteger count = 1;
for(int i = 0; i < 10; i++) {
    CGFloat latDelta = rand()*.035/RAND_MAX - .02;
    CGFloat longDelta = rand()*.03/RAND_MAX - .015;

    CLLocationCoordinate2D newCoord = {coordinate.latitude+latDelta, coordinate.longitude+longDelta};
    MapDemoAnnotation* annotation = [[MapDemoAnnotation alloc] initWithCoordinate:newCoord andID:count++];
    [mapView addAnnotation:annotation];
    [annotation release];
}

and

- (MKAnnotationView *)mapView:(MKMapView *)mapViewLocal viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapViewLocal dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
if(pinView == nil) {
    pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
    pinView.pinColor = MKPinAnnotationColorPurple;
    pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.animatesDrop = YES;
    pinView.canShowCallout = YES;
} else {
    pinView.annotation = annotation;
}
return pinView;

}

Thus, the pins will be set on the map randomly. In my application, the coordinates will change. How to change the coordinates of annotations so that they are updated on the map?

Somebody knows?

+2
source share
3 answers

In the iPhone SDK 3.x, you need to remove the pin annotations and install it again. This is not very nice if you have a lot of annotations on your map.

, / , . , -, - , , . , .

, . , : -)

+2

, . , . .

MKAnnotation, :

@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;

, , , - :

    CLLocation *loc=[[CLLocation alloc] initWithLatitude:55.0 longitude:17.0];
annotation.coordinate=loc.coordinate;
[loc release];
+1

Source: https://habr.com/ru/post/1765138/


All Articles