Am getting this error in my WhereamiAppDelegate.m file:
#import "WhereamiAppDelegate.h" @implementation WhereamiAppDelegate @synthesize window; #pragma mark - #pragma mark Application lifecycle - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Create location manager object - locationManager = [[CLLocationManager alloc]init]; //Make this instance of WhereamiAppDelegate the delegate //It will send its messages to our WhereamiAppDelegate [locationManager setDelegate:self]; //We want all results from the location manager [locationManager setDistanceFilter:kCLDistanceFilterNone]; //And we want it to be as accurate as possible regardless of how //much time/power it takes [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; //Tell our manager to start looking for its location immediately [locationManager startUpdatingLocation]; [locationManager startUpdatingLocation]; - (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation { MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250); [mv setRegion:region animated:YES]; } if(TARGET_IPHONE_SIMULATOR){ [newLocation initWithLatitude:37.33168900 longitude:-122.03073100]; } [mapView setShowsUserLocation:YES]; - (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views { MKAnnotationView *annotationView = [views objectAtIndex:0]; id ,MKAnnotation> mp = [annotationView annotation]; MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 250, 250); [mv setRegion:region animated:YES]; } [self.window makeKey开发者_运维问答AndVisible]; return YES; } - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"%@",newLocation); } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"Could not find location: %@", error); } - (void)applicationWillResignActive:(UIApplication *)application { /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. */ } - (void)applicationDidEnterBackground:(UIApplication *)application { /* Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. If your application supports background execution, called instead of applicationWillTerminate: when the user quits. */ } - (void)applicationWillEnterForeground:(UIApplication *)application { /* Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. */ } - (void)applicationDidBecomeActive:(UIApplication *)application { /* Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. */ } - (void)applicationWillTerminate:(UIApplication *)application { /* Called when the application is about to terminate. See also applicationDidEnterBackground:. */ } #pragma mark - #pragma mark Memory management - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { /* Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. */ } - (void)dealloc { [window release]; [super dealloc]; } @end
Two methods which are causing trouble are:
- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation { MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250); [mv setRegion:region animated:YES]; } if(TARGET_IPHONE_SIMULATOR){ [newLocation initWithLatitude:37.33168900 longitude:-122.03073100]; } [mapView setShowsUserLocation:YES]; - (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views { MKAnnotationView *annotationView = [views objectAtIndex:0]; id ,MKAnnotation> mp = [annotationView annotation]; MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 250, 250); [mv setRegion:region animated:YES]; }
Which generate the "Wrong type argument to unary minus 2" error.
Can you tell me what the problem is?
TIA
You seem to be missing some {brackets} around the body of your -mapView:didUpdateUserLocation: method:
- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250);
[mv setRegion:region animated:YES];
}
if(TARGET_IPHONE_SIMULATOR){
[newLocation initWithLatitude:37.33168900 longitude:-122.03073100];
}
[mapView setShowsUserLocation:YES];
should instead be:
- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250);
[mv setRegion:region animated:YES];
if(TARGET_IPHONE_SIMULATOR){
[newLocation initWithLatitude:37.33168900 longitude:-122.03073100];
}
[mapView setShowsUserLocation:YES];
}
精彩评论