我无法在iphone模拟器中获取当前位置。我将自定义位置设置为埃及的纬度和经度,但没有获得当前位置。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Make this controller the delegate for the map view.
self.MapView.delegate = self;
// Ensure that you can view your own location in the map view.
[self.MapView setShowsUserLocation:YES];
//Instantiate a location object.
locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
//Make this controller the delegate for the location manager.
[locationManager setDelegate:self];
//Set some parameters for the location object.
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}这是委托:
#pragma mark - MKMapViewDelegate methods.
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKCoordinateRegion region;
region = MKCoordinateRegionMakeWithDistance(locationManager.location.coordinate,2000,2000);
[mv setRegion:region animated:YES];
}请任何人帮帮我。
发布于 2012-10-23 19:52:52
到底是什么问题呢?没有在你应该有的地方得到一个userLocation,或者没有把地图区域移动到正确的地方?
如果是第一个问题,那主要是工具问题,而不是代码问题:
如果您的位置位于项目内的gpx文件中,则应能够通过编辑方案/选项/允许位置模拟/并选择默认位置开始

并且您的项目中应该有一个DemoStart.gpx文件,如下所示:
<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
<wpt lat="20.88072" lon="10.67429">
<name>Demo Starting Location</name>
</wpt>
</gpx>(对不起,我太懒了,找不到埃及的确切坐标)。
发布于 2012-10-23 18:47:49
您必须首先确保您的CLLocationManager将他的位置更新为您的位置。为此,将视图控制器设置为CLLocationManager的委托,您已经这样做了,并保存此位置。在完成所有设置后尝试调用startUpdatingLocation,并将showsUserLocation设置为YES。
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power
CLLocation* myLocation = [locations lastObject];
}请确保在>= 5.1版的iOS模拟器上对其进行测试
https://stackoverflow.com/questions/13027511
复制相似问题