iPhone - How do i get direction with degree based location

前端 未结 2 1554
情深已故
情深已故 2021-01-07 12:58

First I\'ve implemented location manager functions in my class and whict are working fine, and gives me the current location. From that location I got how to get location de

2条回答
  •  半阙折子戏
    2021-01-07 13:30

    Use this code and put CLLocationManagerDelegate at .h file

    - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
    {             
        updatedHeading = newHeading.magneticHeading;
        float headingFloat = 0 - newHeading.magneticHeading;
    
        rotateImg.transform = CGAffineTransformMakeRotation(headingFloat*radianConst);    
        float value = updatedHeading;
        if(value >= 0 && value < 23)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° N",value];
        }
        else if(value >=23 && value < 68)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° NE",value];
        }
        else if(value >=68 && value < 113)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° E",value];
        }
        else if(value >=113 && value < 185)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° SE",value];
        }
        else if(value >=185 && value < 203)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° S",value];
        }
        else if(value >=203 && value < 249)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° SE",value];
        }
        else if(value >=249 && value < 293)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° W",value];
        }
        else if(value >=293 && value < 350)
        {
            compassFault.text = [NSString stringWithFormat:@"%f° NW",value];
        }
      }
    

提交回复
热议问题