【问题标题】:Current Location in the Simulator模拟器中的当前位置
【发布时间】:2012-04-29 00:59:16
【问题描述】:

我正在做一个应用程序,我必须在其中找到用户的当前位置。我可以使用 CLLocationmanager 在 iOS 5 模拟器中获取用户的当前位置吗?

【问题讨论】:

    标签: iphone


    【解决方案1】:

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

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

    Add GPX File to Project
    

    格式like this

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:
        - (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 的问题有关吗?
        猜你喜欢
        • 1970-01-01
        • 2017-06-30
        • 2011-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-26
        • 2011-05-11
        相关资源
        最近更新 更多