0
votes

Two questions:

  1. I have LocationManager called from a Singleton. When I run the following code it cycles indefinitely from the moment it is launched. Which I suspect is proicessor and espacially battery intensive. What is the approved method to kill this loop once you have an accurate enough fix?

  2. Can I adapt this to return the Longitude/Latitude (long/lat)?

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

    int degrees = newLocation.coordinate.latitude;

    double decimal = fabs(newLocation.coordinate.latitude - degrees);

    int minutes = decimal * 60;

    double seconds = decimal * 3600 - minutes * 60;

    NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];

    NSLog(@" Current Latitude : %@",lat);

    degrees = newLocation.coordinate.longitude;

    decimal = fabs(newLocation.coordinate.longitude - degrees);

    minutes = decimal * 60;

    seconds = decimal * 3600 - minutes * 60;

    NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];

    NSLog(@" Current Longitude : %@",longt);

}

1

1 Answers

1
votes

1) When you got the location with the required accuracy, just do [manager stopUpdatingLocation]; in the method locationManager:didUpdateToLocation:fromLocation:.
2) To return the coordinate (consisting of latitude and longitude), you could define a property, say @property CLLocationCoordinate2D myCoordinate; in the class that implements locationManager:didUpdateToLocation:, and do there self.myCoordinate = newLocation.coordinate;