adev
unread,Jul 5, 2009, 10:21:52 PM7/5/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to phonegap
Hello.
I have used phonegap for android now I am trying to use it for the
iPhone. I started modifying the location.m file to add heading in
there, but I can't seem to get it quite right. Has anyone added this,
if so, please share if you don't mind.
Here are the changes I made. Please let me know if you see something
way out of place. I am new to obj-c coding.
// --- start
- (void)start:(NSMutableArray*)arguments
withDict:(NSMutableDictionary*)options
{
if (__started == YES)
return;
if ([self.locationManager locationServicesEnabled] != YES)
return;
// Tell the location manager to start notifying us of location
updates
[self.locationManager startUpdatingLocation];
[self.locationManager startUpdatingHeading]; // <--
added to update heading
__started = YES;
if ([options objectForKey:@"distanceFilter"]) {
CLLocationDistance distanceFilter = [(NSString *)[options
objectForKey:@"distanceFilter"] doubleValue];
self.locationManager.distanceFilter = distanceFilter;
}
if ([options objectForKey:@"desiredAccuracy"]) {
int desiredAccuracy_num = [(NSString *)[options
objectForKey:@"desiredAccuracy"] integerValue];
CLLocationAccuracy desiredAccuracy = kCLLocationAccuracyBest;
if (desiredAccuracy_num < 10)
desiredAccuracy = kCLLocationAccuracyBest;
else if (desiredAccuracy_num < 100)
desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
else if (desiredAccuracy_num < 1000)
desiredAccuracy = kCLLocationAccuracyHundredMeters;
else if (desiredAccuracy_num < 3000)
desiredAccuracy = kCLLocationAccuracyKilometer;
else
desiredAccuracy = kCLLocationAccuracyThreeKilometers;
self.locationManager.desiredAccuracy = desiredAccuracy;
}
}
- (void)stop:(NSMutableArray*)arguments
withDict:(NSMutableDictionary*)options
{
if (__started == NO)
return;
if ([self.locationManager locationServicesEnabled] != YES)
return;
[self.locationManager stopUpdatingLocation];
[self.locationManager stopUpdatingHeading]; // <--
added to update/stop heading
__started = NO;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
didUpdateHeading:(CLHeading *)newHeading // <-- get
heading
{
int epoch = [newLocation.timestamp timeIntervalSince1970];
float course = -1.0f;
float speed = -1.0f;
#ifdef __IPHONE_2_2
course = newLocation.course;
speed = newLocation.speed;
#endif
NSString* coords = [NSString stringWithFormat:@"coords: { latitude:
%f, longitude: %f, altitude: %f, heading: %f, speed: %f, accuracy:
{horizontal: %f, vertical: %f}, altitudeAccuracy: null, trueHeading:
%f}",
newLocation.coordinate.latitude,
newLocation.coordinate.longitude,
newLocation.altitude,
course,
speed,
newLocation.horizontalAccuracy,
newLocation.verticalAccuracy,
newHeading.trueHeading // <-- new heading param
];
NSString * jsCallBack = [NSString
stringWithFormat:@"navigator.geolocation.setLocation({ timestamp: %d,
%@ });", epoch, coords];
NSLog(@"%@", jsCallBack);
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
}
// --- end
I am wondering if I need to separate the location and the heading
updates.
I do have a 3GS with a developers license.
Thanks.
Mike