【发布时间】:2014-10-18 14:52:12
【问题描述】:
我一直试图在 iOS 模拟器中伪造我的位置,但我一直在阅读的方法不起作用。我已经使用调试器设置了我的假位置,并在 Debug->Location->Custom Location 中创建了一个自定义位置,但我仍然记录 0.000 0.000 的经纬度。 我正在使用此代码查找当前位置。
- (IBAction)currentLocationButtonPressed:(UIButton *)sender
{
//Search for pubs and bars in current location.
//Push to tableViewController
NSLog(@"current location Pressed.");
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // Best accuracy
[locationManager startUpdatingLocation];
NSLog(@"%@",[self deviceLocation]);
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
NSLog(@"Latitude: %f Longitude: %f", currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
}
}
- (NSString *)deviceLocation {
return [NSString stringWithFormat:@"latitude: %f longitude: %f", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
}
委托已设置,我正在请求授权。
- (void)viewDidLoad {
[super viewDidLoad];
searchLocationTextField.delegate = self;
locationManager.delegate = self;
locationManager = [[CLLocationManager alloc]init];
[locationManager requestWhenInUseAuthorization]; // For foreground access
[locationManager requestAlwaysAuthorization]; // For background access
}
【问题讨论】:
-
在运行模拟器时,您还可以从 xcode 模拟当前位置: 'Debug' -> 'Simulate Location' 。你试过吗?
-
是的,我试过了。没用。 @AsifAsif
-
我认为从这个意义上说,对当前位置进行存根会更有意义。
标签: ios objective-c geolocation ios-simulator