【发布时间】:2015-01-16 03:36:18
【问题描述】:
我的应用程序中的地图视图出现问题。我创建了一个按钮,单击该按钮应在地图上显示用户位置,但没有任何反应(没有错误消息出现)。
我认为问题可能在于我编写代表的方式。相关 .h 和 .m 文件的代码如下:
mapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface mapViewController : UIViewController {
MKMapView *mapview;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapview;
-(IBAction)setMap:(id)sender;
-(IBAction)getCurrentLocation:(id)sender;
@property (nonatomic, retain) IBOutlet CLLocationManager *locationManager;
@end
mapViewController.m
#import "mapViewController.h"
@interface mapViewController ()
@end
@implementation mapViewController {
CLLocationManager *locationManager;
}
@synthesize mapview;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.requestWhenInUseAuthorization;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)setMap:(id)sender {
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
mapview.mapType = MKMapTypeStandard;
break;
case 1:
mapview.mapType = MKMapTypeSatellite;
break;
case 2:
mapview.mapType = MKMapTypeHybrid;
break;
default:
break;
}
}
-(IBAction)getCurrentLocation:(id)sender {
mapview.showsUserLocation = YES;
}
@end
任何帮助将不胜感激,谢谢
【问题讨论】:
-
您期望发生什么?操作如何与 Interface Builder 中的按钮相关联?
-
正如我上面提到的,当点击按钮时,它应该在地图上显示用户的位置。我有一个已发送的事件(内部修饰)连接到指向 getCurrentLocation 的按钮
-
您的问题仍然不清楚,但是从文档中可以看出:“此属性并不表示用户的位置是否在地图上实际可见,仅表示地图视图是否应尝试显示它。” .除了将该属性设置为 YES 之外,您还必须设置中心坐标和(可能)缩放以获得我推断您正在寻找的行为。
标签: ios8 mapkit location-services