我在我的应用程序上使用MKMapView。我需要在模拟器上显示当前位置。
有没有可能。在模拟器上显示当前位置。
发布于 2013-07-16 13:53:34
self.mapView.delegate = self;
self.mapView.showsUserLocation = YES;这将显示MkMapview中的当前位置。
如果您使用的是界面生成器,在属性检查器中,我们有一个具有选项Show User Location的选项Behaviour,选中该选项也会执行相同的操作。
如果在模拟器中看不到,
使用CLLocationManager,我们还可以获取当前位置,将Corelocation FrameWork导入到项目
在.h文件中
#import <CoreLocation/CoreLocation.h>
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) CLLocation* currentLocation;在.m文件中
if ([CLLocationManager locationServicesEnabled] )
{
if (self.locationManager == nil )
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kDistanceFilter; //kCLDistanceFilterNone// kDistanceFilter;
}
[self.locationManager startUpdatingLocation];
}委托函数:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
self.currentLocation = [locations lastObject];
// here we get the current location
}希望这个答案对你有所帮助。
https://stackoverflow.com/questions/3974703
复制相似问题