MapKit code pin personnalisé annotation

J'ai les fichiers suivants:

annotation.h:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface annotation : NSObject <MKAnnotation>

@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *subtitle;


@end

annotation.m:

#import "annotation.h"

@implementation annotation

@synthesize coordinate, title, subtitle;

@end

Et dans le code principal, qui prend dans un NSURL constaté ailleurs:

[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[spinner stopAnimating];

//json parsing
results = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];

NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
annotation * myAnn;

NSArray *pins = mapView.annotations;

if ([pins count])
{
    [mapView removeAnnotations:pins];
}

/* loop through the array, each key in the array has a JSON String with format:
 * title <- string
 * strap <- string
 * id <- int
 * date <- date
 * lat <- floating point double
 * long <- floating point double
 * link <- string

 */
int i;

for (i = 0; i < [results count]; i++) {
    //NSLog(@"Result: %i = %@", i, results[i]);
    //NSLog(@"%@",[[results objectAtIndex:i] objectForKey:@"long"]);

    myAnn = [[annotation alloc] init];
    location.latitude = (double)[[[results objectAtIndex:i] objectForKey:@"lat"] doubleValue];
    location.longitude = (double)[[[results objectAtIndex:i] objectForKey:@"long"] doubleValue];
    myAnn.coordinate = location;
    myAnn.title = [[results objectAtIndex:i] objectForKey:@"title"];
    myAnn.subtitle = [[results objectAtIndex:i] objectForKey:@"strap"];

    [locations addObject:myAnn];

    //NSLog(@"%i", [[results objectAtIndex:i] objectForKey:@"lat"]);
}

[self.mapView addAnnotations:locations];

Précédente choses que j'ai regardé pour dire ce que j'ai besoin d'utiliser MKAnnotationView par opposition à MKPinAnnotationView mais comme vous pouvez le voir, je n'utilise pas non plus, est-il possible pour moi d'utiliser des images personnalisées pour les broches qui sont déposés sur l'écran.

  • Quelle est votre question?
  • Désolé, modifier. J'ai besoin d'utiliser une image personnalisée au lieu de l'habituel rouge pin
InformationsquelleAutor Josh Boothe | 2013-04-14