Hello, I have a pretty simple app that displays the users current location on a map, but unfortunately i'm having some issues and was hoping someone here could help, since my search results were fruitless.
I call [myMapView setShowsUserLocation:YES]; in the application:didFinishLaunchingWithOptions: methods in myAppDelegate.m file, which successfully puts the little blue dot of my map of my location (well, Apple HQ, since I'm using the simulator.)
I have also implemented the mapView:didAddAnnotationViews: method, but unfortunately it never runs, which it should after it adds the blue dot annotation to my map. Any ideas? I will post the relevant code below. Thanks!
myAppDelegate.h
myAppDelegate.m
I call [myMapView setShowsUserLocation:YES]; in the application:didFinishLaunchingWithOptions: methods in myAppDelegate.m file, which successfully puts the little blue dot of my map of my location (well, Apple HQ, since I'm using the simulator.)
I have also implemented the mapView:didAddAnnotationViews: method, but unfortunately it never runs, which it should after it adds the blue dot annotation to my map. Any ideas? I will post the relevant code below. Thanks!
myAppDelegate.h
Code:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface myAppDelegate : NSObject
<UIApplicationDelegate, CLLocationManagerDelegate, MKMapViewDelegate>
{
UIWindow *window;
CLLocationManager *locationManager;
IBOutlet MKMapView *myMapView;
// Other irrelevant stuff is here too
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
myAppDelegate.m
Code:
#import "myAppDelegate.h"
@implementation myAppDelegate
@synthesize window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create location manager object
locationManager = [[CLLocationManager alloc] init];
// Make this instance of myAppDelegate 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 mapView to show the location on map
[myMapView setShowsUserLocation:YES];
[window makeKeyAndVisible];
return YES;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@", newLocation);
NSLog(@"%@", oldLocation);
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Could not find location: %@", error);
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
NSLog(@"mapView:didAddAnnotationViews works!");
// This doesn't run :(
}
//Other methods...
@end