首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone全球定位系统

iPhone全球定位系统
EN

Stack Overflow用户
提问于 2009-07-08 05:53:24
回答 1查看 1.8K关注 0票数 0

我想在objective C中的iPhone上获得我的经度和纬度。有人能指导我如何以编程方式获得这些坐标吗?

代码语言:javascript
复制
#import <Foundation/Foundation.h>

@class CLLocationManager;

@interface CLLocationController : NSObject {
    CLLocationManager *locationManager; 
}

@property (nonatomic, retain) CLLocationManager *locationManager; 

@end

代码语言:javascript
复制
/Hab/Folder/Classes/CLLocationController.m:10:30: error: CLLocationManager.h: No such file or directory
/Hab/Folder/Classes/CLLocationController.m:21: warning: receiver 'CLLocationManager' is a forward class and corresponding @interface may not exist
/Hab/Folder/Classes/CLLocationController.m:22: error: accessing unknown 'delegate' component of a property
EN

回答 1

Stack Overflow用户

发布于 2009-07-08 06:03:02

使用CLLocationManager,将一个对象设置为代理,然后开始获取更新。

代码语言:javascript
复制
self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
self.locationManager.delegate = self; 
[self.locationManager startUpdatingLocation]; 

然后实现委托:

代码语言:javascript
复制
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { 
  NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]); 
  NSLog([NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude]); 
} 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1096307

复制
相关文章

相似问题

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