首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >管理LocationManager didUpdateLocation

管理LocationManager didUpdateLocation
EN

Stack Overflow用户
提问于 2013-06-22 08:01:27
回答 1查看 374关注 0票数 0

两个问题:

  1. 我接到一个单身人的电话叫LocationManager。当我运行下面的代码时,它从启动的那一刻起就会无限期地循环。我怀疑这是忏悔者,尤其是电池密集。什么是批准的方法,以杀死这个循环,一旦你有一个足够准确的修复?

  1. 我可以调整这个来返回经度/纬度(长/纬度)吗?

代码语言:javascript
复制
- (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); 

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-22 08:26:42

1)当您获得所需精度的位置时,只需在方法[manager stopUpdatingLocation];中执行locationManager:didUpdateToLocation:fromLocation:

2)要返回坐标(包括纬度和经度),可以在实现locationManager:didUpdateToLocation:的类中定义一个属性,比如locationManager:didUpdateToLocation:,并在那里执行self.myCoordinate = newLocation.coordinate

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17248632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档