0

For some reason my Map wont present the Users location when button "GetLocation" is pressed. I also made sure "GetLocation" is delegated to the button on the viewcontroller. I have compared my code with others in this forum and been stuck on this matter for quite a while..

//ViewController .h

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

@interface testmap : UIViewController <MKAnnotation, MKMapViewDelegate,  CLLocationManagerDelegate> {

IBOutlet MKMapView *mapView;
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;

}

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *name;
@property(nonatomic, retain) IBOutlet MKMapView *mapView;
@property (strong) CLLocationManager *locationManager;
- (id)initWithLocation:(CLLocationCoordinate2D)coord;
- (IBAction)GetLocation:(id)sender;


@end

//ViewController .m

 #define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
 #import "testmap.h"

 - (NSString *)deviceLocation {
return [NSString stringWithFormat:@"latitude: %f longitude: %f", self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude];
  }

 - (IBAction)GetLocation:(id)sender; {
 self.locationManager = [[CLLocationManager alloc] init];
 self.locationManager.delegate = self;

self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;

 if (IS_OS_8_OR_LATER) {
    [self.locationManager requestWhenInUseAuthorization];
    [self.locationManager requestAlwaysAuthorization];
    [self.locationManager startUpdatingLocation];

 }

  mapView.showsUserLocation = YES;

  }


  -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

 if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {
    self.mapView.showsUserLocation = YES;
    self.mapView.showsPointsOfInterest = YES;
 }

 }


 - (void)didReceiveMemoryWarning
 {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
 }
Ben
  • 91
  • 1
  • 6
  • Have you implemented the delegate methods? If yes can you update the question by adding them? If you have not implemented them, so should do it, because those are the methods where you will get location methods. – Vivek Molkar May 07 '15 at 09:28
  • [This Guide](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html) should help. – Vivek Molkar May 07 '15 at 09:29

0 Answers0