开发者

add overlays to existing pins in viewcontroller.m

I'm new to programming and obj-c and currently working on a map based iphone app which will locate different sport facilities. I want each pin to show a different overlay, for instance a picture overlay will do fine, I'll add pics into the resource folder and I want each pin to reveal a different picture by clicking it. My example only includes one pin with its cordinates. Now, I have now clue where to start, hope u can help me out!

thanks in advance :)

Here's my code:

[mapView addAnnotation:[MapLocation mapLocationtWithTitle:@"Beckomberga Sim och Sporthall" subtitle:@"Söderberga Allé 80" andCoordinate:(CLLocationCoordinate2D){ 59.35817, 17.89740 }]]; 
}

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnot开发者_开发问答ation>)annotation
{
 if([annotation isKindOfClass:[MapLocation class]])
 {
  MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PinAnnotation"];
  pin.canShowCallout = YES;
  pin.animatesDrop = NO;
  pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


   pin.pinColor = MKPinAnnotationColorRed;

   pin.pinColor = MKPinAnnotationColorGreen;

  [pin autorelease];
  return pin;
 }
 return nil;
}


Viktor,

Here is what you need to do:

  • Create a subobject of MKAnnotation that will represent your locations, SportsFacilityLocation
  • That object will contain title, subtitle, and location fields. This is to conform to the MKAnnotation protocol
  • Next you need an object that will be a subclass of MKAnnotationView, SportsFacilityMapView.
  • Finally in your viewForAnnotation delegate method you need to check each annotation type and from that annotation type you will determine to return your SportsFacilityMapView

Check the docs on how to implement the Annotation and then AnnotationView. I have some example code at home that I will post later if you need it. Good Luck!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜