CLLocationManager y grados de la partida en el iPhone
-
20-09-2019 - |
Pregunta
Uso caso didUpdateHeading del objeto CLLocationManager, ¿cómo puedo convertir los valores heading.x y heading.y resultantes en grados puedo trazar en una imagen de una brújula?
Solución
Por rúbricas grados puede utilizar magneticHeading
y trueHeading
propiedades en lugar de x
y y
.
trueHeading
El encabezamiento (medido en grados) con respecto al norte verdadero. (Sólo lectura)
@property(readonly, nonatomic) CLLocationDirection trueHeading
discusión
El valor de esta propiedad representa el título que apunta hacia el Polo Norte geográfico. El valor de esta propiedad siempre se informa en relación con la parte superior del dispositivo, independientemente de la orientación física o interfaz del dispositivo. El valor 0 representa el Norte geográfico, el 90 representa por Oriente, 180 representa al Sur, y así sucesivamente. Un valor negativo indica que el título no se pudo determinar.
Otros consejos
Esta es la forma en que gira el UIImageView con la imagen de una brújula. La aguja del Norte estaba apuntando hacia arriba en un principio la imagen.
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"UIInterfaceOrientationLandscapeLeft");
[self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading - 90) *3.14/180)*-1) )];
}else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
NSLog(@"UIInterfaceOrientationLandscapeRight");
[self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading + 90) *3.14/180)*-1))];
}else if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
NSLog(@"UIInterfaceOrientationPortraitUpsideDown");
[self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading + 180) *3.14/180)*-1) )];
}else{
NSLog(@"Portrait");
[self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((newHeading.magneticHeading *3.14/180)*-1)];
}
Probar:
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
CLLocationDirection trueNorth = [newHeading trueHeading];
CLLocationDirection magneticNorth = [newHeading magneticHeading];
}
CLLocationDirection es typedef doble y para que pueda obtener el título real o magnético en grados.