Skip to content

Instantly share code, notes, and snippets.

@patelrohan
Created March 27, 2012 06:04
Show Gist options
  • Save patelrohan/2213127 to your computer and use it in GitHub Desktop.
Save patelrohan/2213127 to your computer and use it in GitHub Desktop.
MapView
//---------------------------------------Maps Code--------------------------------------
#pragma mark- Maps
-(void)makeAnnotation
{
for (int k=0;k<[annotations count];k++)
{
[self.truckMapView removeAnnotation:[annotations objectAtIndex:k]];
}
[annotations removeAllObjects];
if(app.favTrFlag==YES)
{
for(int i=0;i<[app.trucksLong count];i++)
{
MyAnnotation* myAnnotation1=[[MyAnnotation alloc] init];
point.latitude=[[app.trucksLat objectAtIndex:i] doubleValue];
point.longitude=[[app.trucksLong objectAtIndex:i] doubleValue];
myAnnotation1.coordinate=point;
NSString *m=[NSString stringWithFormat:@"%@:%@",[app.truckID objectAtIndex:i],[app.trucksName objectAtIndex:i]];
myAnnotation1.title=m;
[annotations addObject:myAnnotation1];
[truckMapView addAnnotation:myAnnotation1];
[myAnnotation1 release];
}
}
else
{
for(int i=0;i<[app.trucksLong count];i++)
{
MyAnnotation* myAnnotation1=[[MyAnnotation alloc] init];
point.latitude=[[app.trucksLat objectAtIndex:i] doubleValue];
point.longitude=[[app.trucksLong objectAtIndex:i] doubleValue];
myAnnotation1.coordinate=point;
// NSString *m=[NSString stringWithFormat:@"%@:%@ (%@)",[app.truckID objectAtIndex:i],[app.trucksName objectAtIndex:i],[app.trucksDist objectAtIndex:i]];
NSString *m=[NSString stringWithFormat:@"%@:%@",[app.truckID objectAtIndex:i],[app.trucksName objectAtIndex:i]];
myAnnotation1.title=m;
//myAnnotation1.title=@"Mind It..!";
myAnnotation1.tagg = @"1";
[annotations addObject:myAnnotation1];
[truckMapView addAnnotation:myAnnotation1];
[myAnnotation1 release];
}
MKMapRect flyTo = MKMapRectNull;
for (id <MKAnnotation> annotation in annotations)
{
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(flyTo))
{
flyTo = pointRect;
}
else
{
flyTo = MKMapRectUnion(flyTo, pointRect);
//NSLog(@"else-%@",annotationPoint.x);
}
}
truckMapView.visibleMapRect = flyTo;
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
//static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:@"markerAnnotationView"] autorelease];
pinView.pinColor=MKPinAnnotationColorRed;
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
// rightButton.tag=
//[rightButton setTag:k];
[rightButton addTarget:self
action:@selector(showTruckProfile:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment