1

I am trying to create an application that opens with a map using MKMapView, and then by creating a delegate to CLLocationManger find the current location of the user.

I have posted my code below. The problem that I am having right now is that that although the map does appear when opening the this the simulator it does not give a position or a new heading from the NSLog that should be passing the latitude and longitude.

I am new to Objective - C and App Development, does anyone see if I am missing some of the protocol for CLLocationManger? Thanks for all your help.

Sorry the code is a little sloppy, pasted it in quickly.

  #import "ViewController.h"
  #import <MapKit/MapKit.h>
  #import <CoreLocation/CoreLocation.h>

  @interface ViewController () <CLLocationManagerDelegate>
  @property (nonatomic,strong)CLLocationManager * myLocationManger;
  @property (nonatomic,strong) IBOutlet MKMapView *myMapView;
  @end

  @implementation ViewController

  - (void)viewDidLoad {
      [super viewDidLoad];
      NSLog(@"insdie view did load");

     //    Setting the map to be big as the view
      self.myMapView =[[MKMapView alloc]init];

//Initial Property to Map
     self.myMapView =[[MKMapView alloc] init];

//Set type to Standard
self.myMapView.mapType = MKMapTypeStandard;

//Set Mask for AutoReszing
self.myMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth |                                              UIViewAutoresizingFlexibleHeight;

//Add the View!
[self.view addSubview:self.myMapView];

///*Now lets Use my CLLocation Manager to Locate the iPhone's Posistion*////



//Chekcs if Location Services are Enabled
if ([CLLocationManager locationServicesEnabled]) {
    self.myLocationManger = [[CLLocationManager alloc] init];
    self.myLocationManger.delegate = self;

    [self.myLocationManger startUpdatingLocation];



}
else{
    //Location Services are available we will need software to ask to turn this On
    //The user is SOL if they refuse to turn on Location Services
    NSLog(@"Location Services not enabled");


}



}

  -(void)locationManager:(CLLocationManager *)manager
      didUpdateToLocation:(CLLocation *)newLocation
      fromLocation:(CLLocation *)oldLocation
  {
      //This method will show us that we recieved the new location
      NSLog(@"Latitude = %f",newLocation.coordinate.latitude );
      NSLog(@"Longitude =%f",newLocation.coordinate.longitude);

  }

  -(void)locationManager:(CLLocationManager *)manager
   didFinishDeferredUpdatesWithError:(NSError *)error{
      NSLog(@"Error with Updating");
  }



  -(void)locationManager:(CLLocationManager *)manager
  didFailWithError:(NSError *)error
  {
//Failed to recieve user's location
NSLog(@"failed to recived user's locatio");
  }
1
  • Go through the "Location and Maps Programming Guide". There is an entry that must be added to your Info.plist.
    – rmaddy
    Oct 31, 2014 at 2:01

1 Answer 1

3

I found that in the new iOS 8, you need two keys added to the Plist. This article explains the process beautifuly.

http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

Not the answer you're looking for? Browse other questions tagged or ask your own question.