Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iphone GPS is not giving accurate latitude and longitude

Hello Friend i have seen many post regarding accuracy problem with gps but its not working all the time

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

    NSString  *latstr = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
    NSString  *longstring=[NSStringstringWithFormat:@"%f",newLocation.coordinate.longitude];

     if (abs(howRecent)>5.0)
     {
         [self.locationManager startUpdatingLocation];
         return;
      }
    if(abs(newLocation.horizontalAccuracy)<0.0f)
    {
        [self.locationManager startUpdatingLocation];
        return;
    }
    if(newLocation.horizontalAccuracy>65.0f)
    {
        [self.locationManager startUpdatingLocation];
        return;
    }
    self.latstring = [latstr copy];
    self.longstr = [longstring copy];

    if((updateLocationFirst||loadFirstView))
    {    
        [[NSUserDefaults standardUserDefaults]setObject:latstring forKey:@"Latitude"];
        [[NSUserDefaults standardUserDefaults]setObject:longstr forKey:@"Longitude"];
        [self displayParticularDaySpecial];
        loadFirstView=FALSE;
        updateLocationFirst=FALSE;
        [self.locationManager stopUpdatingLocation];
    }
}

Here the problem is I am sending the latitude and longitude to the google api with respect to some addresses if i am decreasing the accuracy value its taking lot of time to load and this value is having problem when you reach at destination with respect to destination with 0.6 miles difference.

like image 281
Amit Kumar Vashishtha Avatar asked Oct 22 '22 09:10

Amit Kumar Vashishtha


1 Answers

You should refer to the Location Awareness Programming Guide which provides excellent programming examples for determining your location.

As you'll see in the demo in that document, when you start the standard location manager, you generally tell it what accuracy you require. And once you start the location manager, you don't have to start it again (like you appear to be doing in your code sample). The didUpdateLocations method will be called again and again, with increasing accuracy, all on its own. You don't need to start the location manager again ... it keeps going until you turn it off. By definition, if you're in didUpdateLocations, it means it's already on.

I also notice that you're using the old didUpdateToLocation. If you're programming for iOS 6, you really want to use didUpdateLocations, which is the current version of that CLLocationManagerDelegate method.

Finally, you mention it takes a long time to get your location. That's very possible. In fact, in certain areas, you will never get very close (or any location at all). Your app should assume that accurate locations will take a while, and you should gracefully handle if you never get a really accurate location, which is very possible.

like image 169
Rob Avatar answered Nov 01 '22 19:11

Rob