Frustrated! Blue Dot doesn't show up


#1

Hey all, I’m running Xcode 4 with iOS 5 and I followed the instructions in the book and no blue dot. All my Outlets/delegates are connected in the XIB file but nothing. Frameworks are also in place. Here’s my code. Any help is greatly appreciated!

damien

AppDelegate.h

//
//  AppDelegate.h
//  Whereami
//
//  Created by damien AVILES on 11/22/11.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate, MKMapViewDelegate>
{
    CLLocationManager *locationManager;
    
    IBOutlet MKMapView *worldView;
    IBOutlet UIActivityIndicatorView *activityIndicator;
    IBOutlet UITextField *locationTitleField;
    
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;

- (void)dealloc
{
    if ([locationManager delegate] == self)
        [locationManager setDelegate:nil];
    
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    
    
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    
    
    //[locationManager startUpdatingLocation];
    [worldView setShowsUserLocation:YES];
    
    //[locationManager startUpdatingHeading];
    
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (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, this method is called instead of applicationWillTerminate: when the user quits.
     */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    /*
     Called as part of the 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.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"%@", newLocation);
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"Coud not find error: %@",error);
}

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    NSLog(@"HEADING: %@",newHeading);
}

@end

#2

I was having this issue too and the answer turned out to be in the Attributes inspector – make sure to click on the MapView and then click on ‘Show User Location’. The blue dot instantly showed up after that. Hopefully that solves your problem! :smiley:


#3

I think there is a mistake in your code. Please check the method

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:

There you have left the line:
self.window.backgroundColor = [UIColor whiteColor];

I think you are supposed to delete or comment out this line. See if this helps.


#4

Hey guys, thanks for the response. I commented out the line and nothing. I also added to “Show user location” in the XIB file, nothing works. Any other ideas… anybody???

Thanks all!!


#5

Are you on the simulator? Do you have internet connection? Wireless signal?


#6

I had the same problem, on a non-wireless system.

The solution is built into the Simulator:
Go to the simulator menu Debug -> Location and set a location. That will simulate a location, and I think it can even generate a location moving over time.


#7

The issue you are experiencing is due to the fact that you are running ios5. I ran into the same problem. The fix is easy. Under the method to show the user location enter this method: [worldView setUserTrackingMode: MKUserTrackingModeFollow animated:YES]