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

标签 iphone

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

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

同一设备位置的谷歌地图坐标如下 <+26.860524,+75.761569>

Google map 坐标是正确的,但 iPhone 坐标是错误的,这些坐标与 Google map 的准确坐标相差 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

最佳答案

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

另外,请检查 timestamphorizontalAccuracy CLLocation的交付给 locationManager:didUpdateToLocation:fromLocation: 的对象。如果位置测量结果看起来比您想要的更旧或不太准确,请设置一个计时器并等待发送更多位置测量结果。核心位置通常会快速提供缓存和/或不精确的位置,然后进行更准确的精细位置测量。

关于iphone - 如何使用 iPhone CLLocationManager 获取精确坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8401434/

相关文章:

iphone - iPhone应用程序崩溃,崩溃日志已发布

iphone - 单击 UISearchbar (searchDisplayController) 时应用程序崩溃

iphone - 跳转到UITabBarViewController中的另一个ViewController

iphone - OSX 上 Sprite 动画的 "UIImageView"相当于什么?

iphone - 旧显示在模态视图 Controller 后下移问题

iphone - [NSCFString viewWillAppear :]: unrecognized selector sent to instance on iPhone 3G but not on simulator or iPhone 4

iphone - TableView - 信号 SIGABRT

iphone - 在 iOS 设备上访问以编程方式创建的日历

iphone - 如何在同步函数调用中处理异步回调?

Objective C 的 Javascript 语法荧光笔