iPhone - How do i get direction with degree based location

前端 未结 2 1533
情深已故
情深已故 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];
        }
      }
    
    0 讨论(0)
  • 2021-01-07 13:36

    This is actually very simple. Latitudes begin at 0° at the equator with the north pole being 90.0 and the south pole being -90.0. Basically, if the latitude is between 0 and 90, you're in the northern hemisphere and the southern hemisphere for latitude between 0 and -90.

    Longitude basically works the same way. 0° refers to the prime meridian which is the imaginary line that runs through Greenwich, England and a part of Africa. A positive longitude up to 180° refers to locations east of the prime meridian, while negative longitudes refer to areas west of the prime meridian up to 180°.

    0 讨论(0)
提交回复
热议问题