两个问题:
我从Singleton调用了LocationManager。当我运行以下代码时,它从启动的那一刻起无限循环。我怀疑是proicessor和espacially电池密集型。一旦准确到足够的修复,杀死此循环的批准方法是什么?
我可以调整它以返回经度/纬度(长/纬度)吗?
(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;
双秒=十进制* 3600 - 分钟* 60;
NSString * lat = [NSString stringWithFormat:@“%d°%d'%1.4f \”“, 度,分,秒];
NSLog(@“Current Latitude:%@”,lat);
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
分钟=小数* 60;
秒=小数* 3600 - 分钟* 60;
NSString * longt = [NSString stringWithFormat:@“%d°%d'%1.4f \”“, 度,分,秒];
NSLog(@“当前经度:%@”,longt);
}
答案 0 :(得分:1)
1)当您获得具有所需准确度的位置时,只需在方法[manager stopUpdatingLocation];
中执行locationManager:didUpdateToLocation:fromLocation:
。
2)要返回坐标(包括纬度和经度),您可以在实现@property CLLocationCoordinate2D myCoordinate;
的类中定义一个属性,例如locationManager:didUpdateToLocation:
,然后执行self.myCoordinate = newLocation.coordinate
;