そこで、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];
}