如何使用iPhone CLLocationManager获取精确坐标

时间:2011-12-06 14:23:41

标签: iphone

我正在使用CLLocationManager * locationManager并获取坐标,但这些坐标并不像谷歌地图坐标那样精确。

iPhone坐标如下 < + 26.86126232,+ 75.75962328> +/- 100.00m(速度-1.00 mps / course-1.00)

相同设备的位置地点坐标的谷歌地图坐标如下 1 + 26.860524,+ 75.761569>

Google地图坐标是正确的,但iPhone坐标错误,这些距离谷歌地图的精确坐标距离为100米。

如何获得准确的坐标。

 //  MyCLController.h
 //  mapCurrentLocation
 //
 //  Created by mac on 18/11/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.

//

  #import <Foundation/Foundation.h>
  @protocol MyCLControllerDelegate 
  @required
 - (void)locationUpdate:(CLLocation *)location;
 - (void)locationError:(NSError *)error;
  @end


@interface MyCLController : NSObject<CLLocationManagerDelegate> {
   IBOutlet UILabel *locationLabel;
CLLocationManager *locationManager; 
id delegate;
}
@property (nonatomic, retain) CLLocationManager *locationManager;  
@property (nonatomic, assign) id  delegate;
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation;

- (void)locationManager:(CLLocationManager *)manager
     didFailWithError:(NSError *)error;
 @end



 //
 //  MyCLController.m
 //  mapCurrentLocation
//
//  Created by mac on 18/11/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "MyCLController.h"


@implementation MyCLController
@synthesize locationManager;
@synthesize delegate;

- (id) init {
self = [super init];
if (self != nil) {
    self.locationManager = [[[CLLocationManager alloc] init] autorelease];
    self.locationManager.delegate = self; // send loc updates to myself
}
return self;
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
   // NSLog(@"Location: %@", [newLocation description]);
    [self.delegate locationUpdate:newLocation];
}

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error
{
    //NSLog(@"Error: %@", [error description]);
    [self.delegate locationError:error];
}

- (void)dealloc {
    [self.locationManager release];
    [super dealloc];
}

@end



and here i am using this class--

#import "mapCurrentLocationViewController.h"

@implementation mapCurrentLocationViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

- (void)viewDidLoad {
    locationController = [[MyCLController alloc] init];
    locationController.delegate = self;
    [locationController.locationManager startUpdatingLocation];

}
- (void)locationUpdate:(CLLocation *)location {
    locationLabel.text = [location description];
}

- (void)locationError:(NSError *)error {
    locationLabel.text = [error description];
}
- (void)dealloc {
    [locationController release];
    [super dealloc];
}
@end

1 个答案:

答案 0 :(得分:1)

要获得最准确的位置测量值,请在locationManager.desiredAccuracy = kCLLocationAccuracyBest;之前设置startUpdatingLocation

另外,请检查传递到timestamp的{​​{1}}个对象的horizontalAccuracyCLLocation。如果位置测量看起来比您想要的更旧或更准确,请设置计时器并等待更多的位置测量结果。核心位置通常会快速提供缓存和/或不精确的位置,然后跟进更精确的精确位置测量。