objective C . get lat/lng information on app delegate.m - objective-c

AppDelegate.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (nonatomic, strong) CLLocationManager * locationManager;
#property (nonatomic, strong) CLLocation *currentLocation;
#end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog(#"11111");
CLLocationManager *manager = [[CLLocationManager alloc] init];
manager.delegate = self;
[manager requestAlwaysAuthorization];
//Here you set the Distance Filter that you need
manager.distanceFilter = kCLDistanceFilterNone;
// Here you set the Accuracy
manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
NSLog(#"startUpdatingLocation");
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
NSLog(#"startUpdatingLocation %#" , status);
[manager startUpdatingLocation];
NSLog(#"22222");
return YES;
}
first problem is that popup that asking permission called by
[manager requestAlwaysAuthorization]; is dismissed just after 0.5sec~3sec. I don't know why it dismiss.
and even if I pressed always approved (I don't know how English version is exactly),
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
status is alway null
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(CLLocation *)newLocation{
// currentLocation = newLocation;
NSLog(#"locationinfor %#! ,,, %#!!!!", newLocation.coordinate.latitude,newLocation.coordinate.longitude);
}
Secondly
for this phase, [manager startUpdatingLocation];
It should go to didUpdateLocations function and should Log
NSLog(#"locationinfor %#! ,,, %#!!!!", newLocation.coordinate.latitude,newLocation.coordinate.longitude);
but It doesn't come to didUpdateLocations.

The problem might be your declaration of CLLocationManager *manager. When you already have a class member CLLocationManager *locationManager defined, why not use that.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog(#"11111");
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
//Here you set the Distance Filter that you need
self.locationManager.distanceFilter = kCLDistanceFilterNone;
// Here you set the Accuracy
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
NSLog(#"startUpdatingLocation");
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
NSLog(#"startUpdatingLocation %#" , status);
[self.locationManager startUpdatingLocation];
NSLog(#"22222");
return YES;
}
Edit : Make sure your Info.plist has descriptive text for User-sensitive data. You could also check for authorization status and request again if authorization is undetermined.
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusNotDetermined) {
[self.locationManager requestAlwaysAuthorization];
}
}

Related

Current Latitude Longitude on Google Map

I am using below code to get current lat long in iOS 8.
.h
#interface DirectionViewController : UIViewController<CLLocationManagerDelegate,GMSMapViewDelegate>
{
CLLocationManager *locationManager;
}
#property (nonatomic, retain) CLLocationManager *locationManager;
.m
#synthesize locationManager;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *latitude = [NSString stringWithFormat:#"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:#"%f", coordinate.longitude];
NSLog(#"dLatitude : %#", latitude);
NSLog(#"dLongitude : %#",longitude);
But here, I am getting 0.00000 value for both latitude and longitude.
Can anybody help me here. How to get current lat long in iOS 8?
Thanks in advance!
AppDelegte.h
#interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate>
{
CLLocation *currentLocation;
}
#property (strong, nonatomic) CLLocationManager *locationManager;
#property (nonatomic, assign) CLLocationCoordinate2D currentLocationCoordinate;
Appdelget.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
locationManager.delegate = self; // we set the delegate of locationManager to self.
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CurrentLatitude=newLocation.coordinate.latitude;
CurrentLongitude=newLocation.coordinate.longitude;
NSLog(#"%f",CurrentLatitude);
NSLog(#"%f",CurrentLongitude);
[locationManager stopUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error);
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Failed to Get Your Location" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
.Plsit add
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
You're not using the proper method to get your coordinates.
once you call startUpdatingLocation, it calls the location manager methods (that you must implement in order for this to work).
There are two of them, [locationManager:didFailWithError:][1]
and [-locationManager:didUpdateLocations:][2]. You should have warnings asking you to add those methods in your .m, with the proper spelling if you haven't done it yet.
didUpdateLocation is called every X seconds and returns coordinates. You have to build your coordinate strings in this very specific method, where the coordinates are set.
From what I could gather,
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
Will give you an array of CLLocation objects containing the location data.
This array always contains at least one object representing the current location.
If updates were deferred or if multiple locations arrived before they could be delivered, the array may contain additional entries.
The objects in the array are organized in the order in which they occurred. Therefore, the most recent location update is at the end of the array.
This means you'll have to get the lastObject of that array for the most recent location.
Here is an example i've found on the web, for what the inside of that method could look. :
CLLocation *newLocation = [locations lastObject];
CLLocation *oldLocation;
if (locations.count > 1) {
oldLocation = [locations objectAtIndex:locations.count-2];
} else {
oldLocation = nil;
}
NSLog(#"didUpdateToLocation %# from %#", newLocation, oldLocation);
MKCoordinateRegion userLocation = MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 1500.0, 1500.0);
[regionsMapView setRegion:userLocation animated:YES];
Make sure to ask for the different permissions beforehand, and that you have them.
Also note that this method is only available since iOS5 and is different in the previous versions. Though it is very unlikely that you still support iOS5, I thought I should mention it.

Why is this code updating location twice every time?

Here is the code, it all works fine but each time I hit the "Get My Location" button it updates the location twice, I cannot find the reason why, any idea's? I have removed much code from below this and it still does it so I know it's in this part somewhere. Thanks.
.h file:
#import <CoreLocation/CoreLocation.h>
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *LatitudeLabel;
#property (weak, nonatomic) IBOutlet UILabel *LongitudeLabel;
#property (weak, nonatomic) IBOutlet UILabel *GPSAccuracyLabel;
#property (weak, nonatomic) IBOutlet UILabel *AltitudeLabel;
#property (weak, nonatomic) IBOutlet UILabel *VerticalAccuracyLabel;
- (IBAction)getCurrentLocation:(id)sender;
#end
#interface MyLocationViewController : UIViewController <CLLocationManagerDelegate>
#end
.m file:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
CLLocationManager *locationManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)getCurrentLocation:(id)sender {
locationManager.delegate = (id)self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error); UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Failed to Get Your Location" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil]; [errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"Location updated: %#", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
_LatitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
_LongitudeLabel.text = [NSString stringWithFormat:#"%.6f", currentLocation.coordinate.longitude];
_GPSAccuracyLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.horizontalAccuracy];
_AltitudeLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.altitude];
_VerticalAccuracyLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.verticalAccuracy];
}
Console output each time I press the button:
2014-11-22 23:49:37.539 MyLocationDemo[914:60b] Location updated: <+10.16863927,+124.75859298> +/- 10.00m (speed 0.00 mps / course -1.00) # 22/11/14 11:49:37 pm Philippine Standard Time
2014-11-22 23:49:37.545 MyLocationDemo[914:60b] Location updated: <+10.16863927,+124.75859298> +/- 10.00m (speed 0.00 mps / course -1.00) # 22/11/14 11:49:37 pm Philippine Standard Time
After a quick look at Apple's documentations, I've noticed that the delegate method you are using, - locationManager:didUpdateToLocation:fromLocation: is deprecated since iOS 6.
Instead, you should use - locationManager:didUpdateLocations:.
Try replacing your code with the code below and see if it make any difference:
EDIT- I've edit the code below to handle the double-call you get.
From your post above I see they are almost simultaneously, So basically we'll check if at least 1 seconds has passed since last call.
There are probably better ways to do it, but that was just at the top of my head...
Haven't checked it in Xcode, but, if I haven't made a typo or something, it should work.
// ViewController.m
#interface ViewController ()
#property (nonatomic, strong) NSDate *lastUpdateTime; // Create a property
#end // to hold current time
- (void)viewDidLoad {
[super viewDidLoad];
self.lastUpdateTime = [NSDate date]; // In viewDidLoad, 'initialize' it
// to get the current time
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
NSTimeInterval passedTime = -[self.lastUpdateTime timeIntervalSinceNow];
// Here we are checking how much seconds have passed since our lastUpdateTime
// Since lastUpdateTime is in the past, the result will be negative, therefore
// the minus sign, so we'll get a positive number
if(passedTime < 1) {
return;
} // Now we check if less than one second have passed. If so, the whole method
// will return. If not, it will just continue executing
CLLocation *currentLocation = [locations lastObject];
self.lastUpdateTime = [NSDate date]; // Don't forget to update the lastUpdateTime
// To hold the new update time
if (currentLocation != nil) {
NSLog(#"Location updated: %#", currentLocation);
_LatitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
_LongitudeLabel.text = [NSString stringWithFormat:#"%.6f", currentLocation.coordinate.longitude];
_GPSAccuracyLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.horizontalAccuracy];
_AltitudeLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.altitude];
_VerticalAccuracyLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.verticalAccuracy];
}
}
#AMI289, your idea worked, no more double call.
I post the final code here in case it helps others, I just added back the locationManager = [[CLLocationManager alloc] init];.
// ViewController.m
#import "ViewController.h"
#interface ViewController ()
#property (nonatomic, strong) NSDate *lastUpdateTime; // create a property to hold current time.
#end
#implementation ViewController {
CLLocationManager *locationManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.lastUpdateTime = [NSDate date]; // In viewDidLoad, 'initialize' it to get the current time
locationManager = [[CLLocationManager alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)getCurrentLocation:(id)sender {
locationManager.delegate = (id)self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
NSTimeInterval passedTime = -[self.lastUpdateTime timeIntervalSinceNow];
// Here we are checking how much seconds have passed since our lastUpdateTime
// Since lastUpdateTime is in the past, the result will be negative, therefore
// the minus sign, so we'll get a positive number
if(passedTime < 1) {
return;
} // Now we check if less than one second have passed. If so, the whole method
// will return. If not, it will just continue executing
CLLocation *currentLocation = [locations lastObject];
self.lastUpdateTime = [NSDate date]; // Don't forget to update the lastUpdateTime
// To hold the new update time
if (currentLocation != nil) {
NSLog(#"Location updated: %#", currentLocation);
_LatutideLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
_LongitudeLabel.text = [NSString stringWithFormat:#"%.6f", currentLocation.coordinate.longitude];
_GPSAccuracyLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.horizontalAccuracy];
_AltitudeLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.altitude];
_VerticalAccuracyLabel.text = [NSString stringWithFormat:#"%.2f", currentLocation.verticalAccuracy];
}
// Stop Location Manager
[locationManager stopUpdatingLocation];
}
#end

Use of undeclared identifier 'locationManager'

I'm trying to follow this tutorial:
http://www.appcoda.com/how-to-get-current-location-iphone-user/
Everything is fine till I add this line:
locationManager = [[CLLocationManager alloc] init];
Then I get the error.
I also get errors for these lines: (Xcode suggests I use "_LongitudeLabel"?
if (currentLocation != nil) {
longitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.longitude];
latitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
}
Any idea what's wrong? Does the tutorial have errors or have I done something wrong?
Thanks!
This is ViewController.m file:
#import "ViewController.h"
#implementation MyLocationViewController {
CLLocationManager *locationManager;
}
#end
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)getCurrentLocation:(id)sender {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"Error" message:#"Failed to Get Your Location" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"didUpdateToLocation: %#", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
longitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.longitude];
latitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
}
}
#end
This is ViewController.h file:
// ViewController.h
// MyLocationDemo
//
// Created by Ian Nicoll on 12/11/14.
// Copyright (c) 2014 Ian Nicoll. All rights reserved.
//
#import <CoreLocation/CoreLocation.h>
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *LatitudeLabel;
#property (weak, nonatomic) IBOutlet UILabel *LongitudeLabel;
#property (weak, nonatomic) IBOutlet UILabel *addressLabel;
- (IBAction)getCurrentLocation:(id)sender;
#end
#interface MyLocationViewController : UIViewController <CLLocationManagerDelegate>
#end
The first issue is an error on your part. You declared locationManager in MyLocationViewController but try to initialize it in the viewDidLoad of ViewController, where it of course does not exist.
The second issue is an issue with the instructions. When you declare an #property, the default behavior is to create an instance variable with an underscore in front of it.
So #property (weak, nonatomic) IBOutlet UILabel *LatitudeLabel; can be accessed as self.latitudeLabel (which goes through the setter/getter) or just _latitudeLabel which accesses the ivar directly. The latter is probably what you want.
Ok so the build now is Succeeded (though I'm not 100& sure I got things right) but now I get a warning for this line: locationManager.delegate = self; - Assigning to 'id'from incompatible type 'ViewControler *const_strong'
Would you know how to fix this warning?
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
CLLocationManager *locationManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)getCurrentLocation:(id)sender {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"Error" message:#"Failed to Get Your Location" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"didUpdateToLocation: %#", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
_LongitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.longitude];
_LatitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
}
}
#end

Objective-c iOS - Can't receive delegate methods in my custom class

My custom class needs to receive the "didUpdateToLocation" CLLocationManagerDelegate method, however i can't seem to make the following code work.
Header file.
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface MyCurrentLocation : NSObject<MKAnnotation,CLLocationManagerDelegate,MKMapViewDelegate>
{
CLLocationCoordinate2D coordinate;
}
#property (nonatomic, assign) CLLocationCoordinate2D coordinate;
#property (nonatomic, copy) CLLocationManager *locationManager;
-(MyCurrentLocation *)init;
#end
Implementation file.
#import "MyCurrentLocation.h"
#implementation MyCurrentLocation
-(BLCurrentLocation *)init
{
self = [super init];
if (self) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.distanceFilter = kCLDistanceFilterNone;
_locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[_locationManager startUpdatingLocation];
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"Did we receive a location?");
}
You have to respond to other delegate methods, such as the error callback. Also, check for the CLLocationManager's + (CLAuthorizationStatus)authorizationStatus class method to determine if you are able to use location services.
I don't know why but maybe you can try to implement this delegate method to see if location service cannot be registered.
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Please make sure Location Service is ON" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alertView show];
}

MKMapView didUpdateUserLocation not being called

I am following the big nerd ranch guide book and have modified my app delegate.h to look like this:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface WhereamiAppDelegate : NSObject <UIApplicationDelegate,CLLocationManagerDelegate, MKMapViewDelegate>
{
IBOutlet UITextField *locationTitleField;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet MKMapView *worldView;
CLLocationManager *locationManager;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
#property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
#property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
The .m looks like this:
#import "WhereamiAppDelegate.h"
#implementation WhereamiAppDelegate
#synthesize window = _window;
#synthesize managedObjectContext = __managedObjectContext;
#synthesize managedObjectModel = __managedObjectModel;
#synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 250, 250);
[worldView setRegion:region animated:YES];
NSLog(#"didUpdateUserLocation is called");
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// 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: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];
[worldView setShowsUserLocation:YES];
// This line may say self.window, don't worry about that
[self.window makeKeyAndVisible];
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);
}
When I open the app it should ZOOM into my location. But it doesn't zoom, so i put an NSLog in the didUpdateUserLocation to see if it was called. But it was never printed, so it wasn't called. How do I fix this?
Same thing happened to me...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[worldView setDelegate:self];
...
}
Thks