estoy usando el siguiente código para obtener la ubicación actual, he añadido el marco CoreLocationcómo obtener la ubicación actual en latitud y longitud en el objetivo c
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Latitude : %@",lat);
//latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Longitude : %@",longt);
//longLabel.text = longt;
}
pero estoy consiguiendo los valores predeterminados, es decir, Latitud: 42 ° 17 '36.8898 "y Longitud: -71 ° 27' 43.1003" donde mi Latitud actual: N 12 ° 56 '11.5624 "y Longitud: E 77 ° 32' 41.0834". Cómo obtener la latitud y la longitud exactas. donde estoy cometiendo el error o necesito agregar cualquier otro método o función o marco.
Gracias de antemano.
¿Has probado en un dispositivo real o simulador? –
¿Ha habilitado servicios de ubicación en su dispositivo? –
@XSlash He probado en el simulador. – shasha