0

两个问题:

  1. 我从单身人士那里调用了 LocationManager。当我运行以下代码时,它从启动的那一刻起无限循环。我怀疑这是处理器,尤其是电池密集型。一旦你有足够准确的修复,什么是批准的方法来终止这个循环?

  2. 我可以调整它以返回经度/纬度(经度/纬度)吗?

- (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); 

}
4

1 回答 1

1

1)当您获得所需精度的位置时,只需[manager stopUpdatingLocation];在方法中执行locationManager:didUpdateToLocation:fromLocation:
2)要返回坐标(由纬度和经度组成),您可以定义一个属性,例如@property CLLocationCoordinate2D myCoordinate;在实现的类中locationManager:didUpdateToLocation:,并在那里执行self.myCoordinate = newLocation.coordinate

于 2013-06-22T08:26:42.493 回答