开发者

How can i draw a compass like iphone 3gs in ios4?

开发者_运维问答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


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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜