2012-04-28 60 views
6

Tôi đang thực hiện một ứng dụng trong đó tôi phải tìm vị trí hiện tại của người dùng. Tôi có thể lấy vị trí hiện tại của người dùng trong trình mô phỏng iOS 5 bằng cách sử dụng CLLocationmanager không?Vị trí hiện tại trong Trình mô phỏng

Trả lời

8

xcode - Sửa Scheme - Chạy you.app - Lựa chọn

kiểm Allow Location mô phỏng, sau đó chọn "Default Location"

Add GPX File to Project 

định dạng like this

-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]; 
    } 
} 
+0

Hy vọng bạn không phiền, tôi đã định dạng câu trả lời của bạn một chút. Nhưng sau lần thứ hai nhìn vào câu trả lời của bạn: bạn có chắc điều này liên quan đến câu hỏi của OP không? –

7

Trong Xcode, bạn có thể chọn vị trí để mô phỏng bằng cách sử dụng nút nhỏ phía trên bảng điều khiển.

enter image description here

Các vấn đề liên quan