2016-07-13 41 views
0

Ist es möglich, die aktuellen iPads Richtung Norden, Osten, Süden oder Westen zum Beispiel von CLLocationManager zu bekommen?Holen iPads Richtung (N, E, S, W)

+0

Ja, es ist genau dort in der Dokumentation für 'CLLocationManager'. Schau dir 'CLHeading' an. –

Antwort

1

Dies ist für den rotierenden Stift in welche Richtung seine Bewegung so könnte es für Sie hilfreich sein und durch Stift Winkel erhalten Sie iPad Richtung.

-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { 
    // Use the true heading if it is valid. 
    CLLocationDirection direction = newHeading.magneticHeading; 
    CGFloat radians = -direction/180.0 * M_PI; 

    self.strAccuracy = [NSString stringWithFormat:@"%.1fmi",newHeading.headingAccuracy];  
    [lblAccuracy setText:self.strAccuracy]; 

    //Rotate Bearing View 
    [self rotateBearingView:bearingView radians:radians]; 

    //For Rotate Niddle 
    CGFloat angle = RadiansToDegrees(radians); 
    [self setLatLonForDistanceAndAngle]; 
    [self rotateArrowView:arrowView degrees:(angle + fltAngle)]; 
} 

-(void)rotateArrowView:(UIView *)view degrees:(CGFloat)degrees 
{ 
    CGAffineTransform transform = CGAffineTransformMakeRotation(DegreesToRadians(degrees)); 
    view.transform = transform; 
} 

-(void)setLatLonForDistanceAndAngle 
{ 
    dblLat1 = DegreesToRadians(appDelegate.dblLatitude); 
    dblLon1 = DegreesToRadians(appDelegate.dblLongitude); 

    dblLat2 = DegreesToRadians(objClsProductSearch.dblLatitude); 
    dblLon2 = DegreesToRadians(objClsProductSearch.dblLongitude); 

    fltLat = dblLat2 - dblLat1; 
    fltLon = dblLon2 - dblLon1; 
} 

-(float)getAngleFromLatLon 
{ 
    //Calculate angle between two points taken from http://www.movable-type.co.uk/scripts /latlong.html 
    double y = sin(fltLon) * cos(dblLat2); 
    double x = cos(dblLat1) * sin(dblLat2) - sin(dblLat1) * cos(dblLat2) * cos(dblLon2); 
    CGFloat angle = RadiansToDegrees(atan2(y, x)); 
    return angle; 
}