2012-04-28 16 views
6

में वर्तमान स्थान मैं एक ऐप कर रहा हूं जिसमें मुझे उपयोगकर्ता का वर्तमान स्थान मिलना है। मुझे CLLocationmanager का उपयोग करके आईओएस 5 सिम्युलेटर में उपयोगकर्ता का वर्तमान स्थान मिलता है?सिम्युलेटर

उत्तर

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

आशा है कि आप कोई आपत्ति नहीं है, मैं अपने जवाब एक सा स्वरूपित। लेकिन आपके उत्तर के दूसरे स्वरूप के बाद: क्या आप वाकई ओपी के सवाल से संबंधित हैं? –

7

Xcode में अनुमति दें, आप कंसोल के ऊपर एक छोटे बटन का उपयोग अनुकरण करने के लिए स्थान का चयन कर सकते हैं।

enter image description here

संबंधित मुद्दे