2012-04-28 124 views

回答

8

的Xcode - 編輯方案 - 運行you.app - 選項

檢查允許位置模擬,然後選擇 「默認位置」

Add GPX File to Project 

格式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

希望你不介意,我格式化了你的答案了一下。但在第二次看到你的答案後:你確定這與OP的問題有關嗎? – 2012-04-28 16:59:39

7

在Xcode中,您可以使用控制檯上方的小按鈕選擇要模擬的位置。

enter image description here