-2

所以我将我的地图视图与 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];



}
4

1 回答 1

0

所以要修复,只需将类型 Annotation 更改为 MapViewAnnotation,并制作数组药房的名称。

于 2013-01-27T01:56:19.720 回答