我有以下文件:
注释.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
注释.m:
#import "annotation.h"
@implementation annotation
@synthesize coordinate, title, subtitle;
@end
在主代码中,它包含NSURL
在其他地方找到的:
[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];
我之前看过的东西说我需要使用MKAnnotationView
而不是MKPinAnnotationView
但你可以看到我不使用任何一个,我是否可以为放置在屏幕上的图钉使用自定义图像。