This is more of a theoretical question than code:
What i did till now :
My app is heavily dependent upon location tracking.
I posted a question about it around 5 hours back without a suitable answer and it is now pretty old to put a new question there .i will closing it after i get an answer for this question.
What i want to do is to have a button that user presses.it makes location manager to start updating locations and then for every 5 feet moved . i want to make iPhone play random sounds.
i implemented correct code given below and now i tested on my device moving from one place to here in my house. through trial and errors i got to know that first few locations are iPhone trying to get an accurate results and are generally to be avoided so i made it a condition to process location which come after more than 2 seconds to previous.
Now my Real ques :
I have my device on wifi.(don’t have gps and can’t have) so after few initial useless location updates . my alerts stop showing.. i was like : why isn’t working . i set it to accuracy best. did filtering to 1.5 meters .. i was moving like 15 feets in the house and no update ?..now i think it is because it is taking locations through wifi and hence it is founding no new locations even if i move 40 feeds around that wifi.? am i correct?
If that is true .. can anyone tell will this work correctly in gps .. for U.S. users..where they have lots of towers.. so that my app will correctly update that new location is at least 5 meters away from its previous location..
Sorry for the long question.. There are too many doubts for me..
-(id) init
{
if(self = [super init])
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
// locationManager.distanceFilter = 1.5;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
return self;
}
return nil;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New Lcoation"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
self.currentLocation = newLocation;
BOOL newLocationIsValid = [self isValidLocation:newLocation withOldLocation:oldLocation];
if(newLocationIsValid && oldLocation)
{
int distance = [newLocation distanceFromLocation:oldLocation];
if(distance >2 && distance <10)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Distance"
message:[NSString stringWithFormat:@"%i meters",distance]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[fileURl release];
}
}
}
-(BOOL)isValidLocation:(CLLocation*)newLocation withOldLocation:(CLLocation*)oldLocation
{
if(newLocation.horizontalAccuracy < 0 )
{
return NO;
}
NSTimeInterval secondsSinceLastPoint = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
if(secondsSinceLastPoint < 0)
{
return NO;
}
if(secondsSinceLastPoint < 2)
{
int distance = [newLocation distanceFromLocation:oldLocation];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Distance"
message:[NSString stringWithFormat:@"%i meters",distance]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
return NO;
}
return YES;
}
yes, doesn’t work because you use wifi for locating. The Location-Service just know where your wifi is, not your position relative to your wifi (that would be nice).
so for your service you must use gps. and even then, the accuracy is not garanteed.
see http://www.kowoma.de/en/gps/accuracy.htm