【问题标题】:Lat,Long values are not accurate to the current location in iphoneLat,Long 值不准确到 iphone 中的当前位置
【发布时间】:2013-01-31 09:16:40
【问题描述】:

我是 IOS 新手,现在我正在开发定位应用程序,但在 iPhone 上运行我的应用程序时,我没有得到正确的纬度、经度值。它给了我当前位置的纬度、经度值太远,为什么它会显示这些值谁能告诉我..

【问题讨论】:

标签: core-location mkmapview


【解决方案1】:

试试看……

设置委托 CLLocationManagerDelegate

#import <CoreLocation/CoreLocation.h>

CLLocationManager *locationManager;
CLLocation *startLocation;


- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *currentLatitude;
    NSString *currentLongitude;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];
    startLocation = nil;
 }

-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    currentLatitude = [[NSString alloc] 
                   initWithFormat:@"%g", 
                   newLocation.coordinate.latitude];



    currentLongitude = [[NSString alloc] 
                    initWithFormat:@"%g",
                    newLocation.coordinate.longitude];

   NSLog(@"%@",currentLatitude);
   NSLog(@"%@",currentLongitude);
}

-(void)locationManager:(CLLocationManager *)manager 
  didFailWithError:(NSError *)error
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"%@",error] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多