-(void) locateAllLocationonMap {
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.04;
span.longitudeDelta=0.04;
region.span=span;
// region.center = currentLocation;
[mapView removeAnnotations:[mapView annotations]];
for (objBean in arrFilter) { ////arrFilter is array data
CLLocationCoordinate2D location;
location.latitude = [objBean.gps_lat doubleValue];
location.longitude = [objBean.gps_long doubleValue];
addAnnotationpins = [[AnnotationPins alloc] init];
addAnnotationpins.objEvent = objBean;
addAnnotationpins.title = objBean.title;
addAnnotationpins.subtitle = [NSString stringWithFormat:@"%@ to %@",objBean.start_date,objBean.end_date];
addAnnotationpins.coordinate = location;
[mapView addAnnotation:addAnnotationpins];
[arrAnnMapRect addObject:addAnnotationpins]; /// arrAnnMapRect is an blank array....
region.center = location;
NSString *device = [[UIDevice currentDevice] model];
if ([device isEqualToString:@"iPhone Simulator"]) {
region.center = location;
}
}
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
[self setMyMapRect];
}
-(void)setMyMapRect{
MKMapRect flyTo = MKMapRectNull;
for (id <MKAnnotation> annotation in arrAnnMapRect) {
NSLog(@"fly to on");
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(flyTo)) {
flyTo = pointRect;
} else {
flyTo = MKMapRectUnion(flyTo, pointRect);
}
}
// Position the map so that all overlays and annotations are visible on screen.
mapView.visibleMapRect = flyTo;
}
No comments:
Post a Comment