Reputation: 2306
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 degrees from here. but I'm not able to get the direction (i.e. North, South, East, West) I've referred this too. I want the location that I'm getting to be displayed in degrees with direction format like this. i.e. location manager gives me +37.33019332,-122.02298792 and i want something like 37° 19' 49"N, -122° 1' 23"E. I'm getting all things just don't know how to get the last "N" and "E".
If i use CLLocation.course
for this I'm getting my direction course.
Any help would be appreciated.
Upvotes: 0
Views: 2172
Reputation: 431
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];
}
}
Upvotes: 2
Reputation: 30846
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°.
Upvotes: 5