模拟器中的当前位置

时间:2012-04-28 05:54:08

标签: iphone

我正在做一个应用程序,我必须找到user.can的当前位置。我通过使用CLLocationmanager获取用户在iOS 5模拟器中的当前位置?

3 个答案:

答案 0 :(得分:7)

xcode - 编辑方案 - 运行you.app - 选项

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

Add GPX File to Project

格式like this

答案 1 :(得分:7)

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

enter image description here

答案 2 :(得分:-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];
    }
}