Can't get code to compile because of error in the - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
method. xCode 4 says that "u" is an undeclared identifier, and so is the "*"
Here is the code in the .m file:
#import "WhereamiAppDelegate.h"
@implementation WhereamiAppDelegate
@synthesize window=_window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Create location manager object
locationManager = [[CLLocationManager alloc]init];
// There will be a warning from this line of code, ignore it for now
[locationManager setDelegate:self];
// We want all results from the Location Manager
[locationManager setDistanceFilter:kCLHeadingFilterNone];
// And we want it to be as accurate as possible
// regardless of how much power it takes
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
// [locationManager startUpdatingLocation];
[worldView setShowsUserLocation:YES];
// Tell our manager to start looking for its location immediately
[locationManager startUpdatingLocation];
[self.window makeKeyAndVisible];
return YES;
}
- (void)locationM开发者_StackOverflow社区anager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@", newLocation);
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Could not find location: %@", error);
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocationCoordinate2D loc = [u coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];
}
Can you please tell me what I need to do to overcome this problem and get the program to compile?
Thank you.
Try
- (void)mapView:(MKMapView*)mapView didUpdateUserLocation:(MKUserLocation*)userLocation
{
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];
}
Your cut and paste missed the serLocation of userLocation.
精彩评论