MKMapView:使用未声明的标识符'ann'?

时间:2013-01-27 01:37:15

标签: objective-c json mkmapview identifier

所以我将我的mapview与MySQL数据库中的坐标结合在一起。我想我差不多了,但由于某些原因,xcode不断向我扔“使用未申报的标识符'ann'”。我究竟做错了什么?这是我的代码......

MapViewAnnotation.h

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

@interface MapViewAnnotation : NSObject <MKAnnotation> {

    CLLocationCoordinate2D coordinate;
    NSString *title;
    NSString *subtitle;


}

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



@end

MapViewAnnotation.M

#import "MapViewAnnotation.h"

@implementation MapViewAnnotation

@synthesize title, coordinate, subtitle;

-(void)dealloc{
    [title release];
    [super dealloc];
}


@end

MapViewController.h

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


@interface MapViewController : UIViewController  <MKMapViewDelegate> 

    @property (nonatomic, strong) IBOutlet MKMapView *mapView;
    @property (nonatomic, retain) NSMutableArray *Dispensaries;
    @property (nonatomic, retain) NSMutableData *data;



@end

MapViewController.m

#import "MapViewController.h"
#import "MapViewAnnotation.h"


@implementation MapViewController
@synthesize mapView;
@synthesize Dispensaries;
@synthesize data;



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad {

[super viewDidUnload];




        NSLog(@"Getting Device Locations");

        NSString *hostStr = @"http://stylerepublicmagazine.com/dispensaries.php";
        NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:hostStr]];
        NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
        id object = [serverOutput JSONValue];
        NSMutableArray *array = (NSMutableArray *)object;

        for (NSDictionary *dictionary in array) {

            CLLocationCoordinate2D coord = {[[dictionary objectForKey:@"lat"] doubleValue], [[dictionary objectForKey:@"lng"] doubleValue]};

            Annotation *ann = [[Annotation alloc] init];
            ann.title = [dictionary objectForKey:@"Name"];
            ann.coordinate = coord;
            [mapView addAnnotation:point];




    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];



    self.mapView.delegate = self;


}

}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];


MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = userLocation.coordinate;
point.title = @"You Are Here";
point.subtitle = @"Your current location";

[self.mapView addAnnotation:point];



}

1 个答案:

答案 0 :(得分:0)

因此,要修复,只需将类型Annotation更改为MapViewAnnotation,并创建阵列药房的名称。