模拟器中的当前位置

7

我正在制作一款应用程序,需要找到用户的当前位置。在iOS 5模拟器中,我是否可以使用CLLocationmanager来获取用户的当前位置?

3个回答

7

xcode - 编辑 Scheme - 运行你的应用程序 - 选项

勾选允许位置模拟,然后选择“默认位置”。

Add GPX File to Project

像这样的格式

,与此链接相关。

7
在Xcode中,您可以使用控制台上方的一个小按钮来选择要模拟的位置。

-4
- (void)viewDidLoad{
    [super viewDidLoad];
    self.title = @"MapView";
    self.navigationController.navigationBarHidden = NO;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
    [locationManager startUpdatingLocation];
}

- (void) loadPin {
    iCodeBlogAnnotation *appleStore1;
    CLLocationCoordinate2D workingCoordinate;
    workingCoordinate.latitude = [latitude doubleValue];
    workingCoordinate.longitude = [longitude doubleValue];
    appleStore1 = [[iCodeBlogAnnotation alloc] initWithCoordinate:workingCoordinate];
    [appleStore1 setTitle:[NSString stringWithFormat:@"Default Point"]];

    //[appleStore1 setSubtitle:[NSString stringWithFormat:@"Distance %.2f Miles",miles]];
    [appleStore1 setAnnotationType:iCodeBlogAnnotationTypeEDU];
    [mapView addAnnotation:appleStore1];
    [(MKMapView*)self.mapView selectAnnotation:appleStore1 animated:NO];
    MKCoordinateRegion region;
    region.center.latitude = [latitude doubleValue];
    region.center.longitude = [longitude doubleValue];
    region.span.latitudeDelta = .5;
    region.span.longitudeDelta = .5;
    [mapView setRegion:region animated:YES];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    latitude = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.latitude];
    longitude = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.longitude];
    [locationManager stopUpdatingLocation];
    if (latitude > 0) {
        [self loadPin];
    }
}

希望你不介意,我稍微调整了一下你的回答。但是在第二次查看你的回答后,你确定这与OP的问题有关吗? - Rok Jarc

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接