showsUserLocation не будет работать по какой-то причине

По какой-то причине моя карта не отображает местоположение пользователей, когда нажата кнопка "GetLocation". Я также удостоверился, что "GetLocation" делегирован кнопке на контроллере представления. Я сравнил свой код с другими на этом форуме и застрял в этом довольно долгое время..

// 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.
 }

0 ответов

Другие вопросы по тегам