我有三个地点。我想在每5秒内随机逐一显示它们。
我使用过这段代码:
-(IBAction)onMap:(id)sender
{
[NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(loadMap)
userInfo:nil
repeats:YES];
}
-(void)loadMap
{
[mapView1 removeAnnotations:mapView1.annotations];
int i = random()%3;
location.latitude = [[lat_Array objectAtIndex:i] doubleValue];
location.longitude =[[long_Array objectAtIndex:i] doubleValue];
CLLocationCoordinate2D center = coordinate;
[mapView1 setCenterCoordinate:center];
NSMutableArray *marketLocations =[[NSMutableArray alloc]init];
MapAnnotation *addAnnotation = [[MapAnnotation alloc] initWithCoordinate:location];
[addAnnotation setTitle:@"name"];
[marketLocations addObject:addAnnotation];
[mapView1 addAnnotations:marketLocations];
// region.center = location;
span.latitudeDelta = 150.0f;
span.longitudeDelta = 150.0f;
region.span=span;
[mapView1 setRegion:region animated:FALSE];
[mapView1 regionThatFits:region];
}
#pragma mark - Mapview delegate
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"];
annView.animatesDrop=FALSE;
annView.canShowCallout = YES;
annView.pinColor = MKPinAnnotationColorPurple;
//annView.rightCalloutAccessoryView = rightButton;
return annView;
}
它正确显示位置,但在每次加载时,它会从用户的滚动中聚焦到非洲。
我不希望这样。我只想留在用户滚动到的位置。