0

I'm trying to make a view like compass in iphone 3gs or iphone4. Do you know somebody how can I start?, I can't find too much information about this issue...I only want to draw an arrow always following the north. I'm using ios 4.0

Thanks in advance

mapega
  • 33
  • 5

1 Answers1

1

Start heading updates with:

if([CLLocationManager headingAvailable]) {
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];

    // myDelegateObject is an instance of a class implementing the CLLocationManagerDelegate protocol
    locationManger.delegate = myDelegateObject;
    [locationManager startUpdatingHeading];
}

Implement the CLLocationManagerDelegate protocol on one of your classes -- in particular, something like:

-(void)locationManager:(CLLocationManager*)manager didUpdateHeading:(CLHeading*)heading {
    // CLLocationDirection is a double typedef
    CLLocationDirection headingInDegrees = heading.magneticHeading;

    // you'll have to implement this in some fashion...
    [myCompassViewController rotateCompassImageToHeading:headingInDegrees];
}
Seamus Campbell
  • 17,816
  • 3
  • 52
  • 60