首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS5.1中的定位服务不能正常工作

iOS5.1中的定位服务不能正常工作
EN

Stack Overflow用户
提问于 2013-06-30 13:10:59
回答 1查看 104关注 0票数 0

我有一个用Objective-C编写的简单应用程序,它使用CLLocationManager等获取我的当前位置。代码在iPhone 6.1模拟器上运行良好,但它不能在我实际的iPod触摸上运行。第三代iPod Touch正在运行iOS5.1,它确实要求用户启用位置服务,但它没有得到更新。如果你问我,我可以发布代码,但我认为只会有一个明显的兼容性问题,这将是一个相当简单的修复。任何帮助都将不胜感激!谢谢!~Carpetfizz

ViewController.h

代码语言:javascript
运行
复制
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
    CLLocationManager* locationManager;
}

@property (weak, nonatomic) IBOutlet UILabel *labelLong;
@property (weak, nonatomic) IBOutlet UILabel *labelLat;
-(IBAction)updateLocaitonButtonAction:(id)sender;
@end

ViewController.m

代码语言:javascript
运行
复制
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize labelLong,labelLat;

- (void)viewDidLoad
{
    [super viewDidLoad];
    locationManager = [[CLLocationManager alloc]init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *location = [locations lastObject];
    NSLog(@"%f,%f",location.coordinate.latitude,location.coordinate.longitude);
    self.labelLong.text = [NSString stringWithFormat:@"%f",location.coordinate.longitude];
    self.labelLat.text  = [NSString stringWithFormat:@"%f",location.coordinate.latitude];
    [locationManager stopUpdatingLocation];
}

-(IBAction)updateLocaitonButtonAction:(id)sender
{
    [locationManager startUpdatingLocation];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-30 17:18:54

只需使用此委托

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

https://stackoverflow.com/questions/17387367

复制
相关文章

相似问题

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