2

I am developing an compass application for iphone 3GS. I have used CoreLocation framework for the compass method I have used...

 - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading

...method for getting the heading.

My question is how to get a value like "315° NW, 90° E,140° SE" without moving the iphone. I do not have 3GS iphone so, if anybody has some ideas, please help.

Thank you.

Frank Shearar
  • 17,012
  • 8
  • 67
  • 94
shivang
  • 91
  • 1
  • 5
  • 1
    It's not a good idea to develop an application for a device you don't have and can't test on. If you are building this for an iPhone 3G S, you need to go get one. – Brad Larson Jan 12 '10 at 15:48
  • I'm not sure I understand what you're asking. Can you clarify your question a bit? If you're asking how to extract the compass heading from a CLHeading object, take a look at its trueHeading or magneticHeading properties. – Ben Gottlieb Jan 12 '10 at 11:42
  • No, i have an arrow pointing straight when user press an start button then compass events start and arrow will move to an fixed point such as 315° NW, 90° E,140° SE etc..so how should i detect the coordinates which are given above.Thank you. – shivang Jan 12 '10 at 12:40
  • when you receive a -locationManager:didUpdateHeading: message, take a look at the magneticHeading property; if it's 90°, that's east, adjust your arrow, etc. Are you asking about how to draw the arrow? – Ben Gottlieb Jan 12 '10 at 13:13

1 Answers1

1

I use this snippet just before the @implementation of the class where I need my fake heading and location data.

#if (TARGET_IPHONE_SIMULATOR)
@interface MyHeading : CLHeading
    -(CLLocationDirection) magneticHeading;
    -(CLLocationDirection) trueHeading;
@end

@implementation MyHeading
    -(CLLocationDirection) magneticHeading { return 90; }
    -(CLLocationDirection) trueHeading { return 91; }
@end

@implementation CLLocationManager (TemporaryLocationFix)
- (void)locationFix {
    CLLocation *location = [[CLLocation alloc] initWithLatitude:55.932 longitude:12.321];
    [[self delegate] locationManager:self didUpdateToLocation:location fromLocation:nil];

    id heading  = [[MyHeading alloc] init];
    [[self delegate] locationManager:self didUpdateHeading: heading];
}

-(void)startUpdatingHeading {
    [self performSelector:@selector(locationFix) withObject:nil afterDelay:0.1];
}

- (void)startUpdatingLocation {
    [self performSelector:@selector(locationFix) withObject:nil afterDelay:0.1];
}
@end
#endif
Niels Castle
  • 8,039
  • 35
  • 56