Getting Longitude/Latitude of the User When the viewDidLoad

后端 未结 5 611
故里飘歌
故里飘歌 2020-12-29 10:22

My purpose is to get the longitude/latitude of the user when the view is loaded and to store the values in two variables for later calculations. I don\'t need to track the u

5条回答
  •  余生分开走
    2020-12-29 10:35

    This worked for me

    - (void)viewDidLoad {
        [super viewDidLoad];
        // locationManager update as location
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self; 
        locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
        locationManager.distanceFilter = kCLDistanceFilterNone; 
        [locationManager startUpdatingLocation];
        [locationManager stopUpdatingLocation];
        CLLocation *location = [locationManager location];
        // Configure the new event with information from the location
    
        float longitude=location.coordinate.longitude;
        float latitude=location.coordinate.latitude;
    
        NSLog(@"dLongitude : %f", longitude);
        NSLog(@"dLatitude : %f", latitude); 
    }
    

提交回复
热议问题