PDA

View Full Version : GPS incorrect, compass GPS correct.. Confused.




R.R.Mac
Jul 17, 2011, 11:11 AM
Hi!

I've made a sailing app which records lots of data. One thing it records is GPS location. I downloaded Locate Me from the apple website as it was under one of the recommended apps. I've also got an app from 'beginning iPhone development'. Both their apps and mine are all giving a GPS location which is incorrect. I've set the accuracy to best and then to 10 metres with no difference in result. However, when I go into the compass and look at the GPS location there, it is almost exactly correct.

This is a navigation app (tried using the navigation accuracy too) and I need the GPS location to be almost spot on. Does anyone know how to do this? The compass app apple provides is perfect, does anyone know what I need to do? I've based my GPS code on that of Locate Me.

Thanks.



robbieduncan
Jul 17, 2011, 11:28 AM
Are you just taking one (the first) location from Location Services? Or do you register to keep getting updates? As they location gets much more accurate over time so you need to keep getting updates.

To get any meaningful help you should post all of your location code with some explanation.

R.R.Mac
Jul 21, 2011, 06:27 AM
Are you just taking one (the first) location from Location Services? Or do you register to keep getting updates? As they location gets much more accurate over time so you need to keep getting updates.

To get any meaningful help you should post all of your location code with some explanation.


I am just taking the first location but the Locate Me app and the app from the book I bought also takes it constantly and yields the same results. My code is below.

What I believe, is that as soon as it finds the location to the accuracy given, it continues with the code and so I should only have to call it once. I could change this but i've basically stolen the code from Locate Me and WhereAmI from the book I bought and they all yield the same results regardless of how long it's been calling for.The compass app gets the accuracy right the first time.

Sorry it's taken so long to reply, i'm actually currently on the boat this app was meant to be used for and so I don't always have internet.



-(void)createObject{

if(listOfObjects == nil){ //listOfObjects is an Array
[self createArrayList];
}

if(locationManager == nil){
gpsObject = [[GPSObject alloc]init]; //this is a GPS object holding coordinates etc
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
}
else{
gpsObject = [[GPSObject alloc]init];
[locationManager startUpdatingLocation];
}

}



- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
// NSLog(@"Updating Location");

if (startingPoint == nil){
self.startingPoint = newLocation;
}

NSDate *dateNow = [[NSDate alloc]init];
gpsObject.startDate = dateNow;



NSString *latitudeStr = [[NSString alloc] initWithFormat:@"%g\u00B0",
newLocation.coordinate.latitude];
gpsObject.latitude = latitudeStr;
[latitudeStr release];

NSString *horizontalAccuracyString = [[NSString alloc]
initWithFormat:@"%gm",
newLocation.horizontalAccuracy];
NSLog(@"%@",horizontalAccuracyString);
[horizontalAccuracyString release];


NSString *longitudeStr = [[NSString alloc] initWithFormat:@"%g\u00B0",
newLocation.coordinate.longitude];
gpsObject.longitude = longitudeStr;
NSLog(@"Longitude is: %@", longitudeStr);
[longitudeStr release];


[listOfObjects addObject:gpsObject]; //adds the object to the list of objects
[gpsObject release];
gpsObject = nil;
[locationManager stopUpdatingLocation]; //stops updating the location
}