2012-04-28 18 views
6

Ich mache eine App, in der ich den aktuellen Standort des Benutzers finden muss. Kann ich den aktuellen Standort des Benutzers im iOS 5 Simulator mit CLLocationmanager abrufen? Schema bearbeiten - -Aktueller Standort im Simulator

Antwort

8

Xcode Lauf you.app - Option

Prüfung zulassen Standort Simulation, dann wählen Sie "Default Location"

Add GPX File to Project 

das Format 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

Hoffe, Sie haben nichts dagegen, ich Ihre Antwort ein bisschen formatiert. Aber nach dem zweiten Blick auf deine Antwort: Bist du sicher, dass dies mit OPs Frage zusammenhängt? –

7

In Xcode, Sie können den zu simulierenden Ort mit einem kleinen Knopf über der Konsole auswählen.

enter image description here

Verwandte Themen