【问题标题】:How do I get exact coordinates using iPhone CLLocationManager如何使用 iPhone CLLocationManager 获取精确坐标
【发布时间】:2011-12-06 14:23:41
【问题描述】:

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

iPhone坐标如下 +/-100.00m(速度-1.00 mps/course-1.00)

同一设备位置坐标的谷歌地图坐标如下

Google 地图坐标正确,但 iPhone 坐标错误,距离 google 地图的准确坐标 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

【问题讨论】:

  • 那么您目前是如何获取坐标的?至少你需要展示一些代码。
  • - (void)viewDidLoad { locationController = [[MyCLController alloc] init]; locationController.delegate = self; [locationController.locationManager startUpdatingLocation]; } - (void)dealloc { [locationController release]; [超级释放]; } - (void)locationUpdate:(CLLocation *)location { locationLabel.text = [位置描述]; } - (void)locationError:(NSError *)error { locationLabel.text = [错误描述]; }
  • 在 MyCLController 类中,我正在定义委托 并创建 CLLocationManager *locationManager 的对象。这个类取自example。
  • 编辑你的帖子并使用代码标签粘贴代码,在评论部分很难阅读。

标签: iphone


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 2011-06-20
    • 2014-07-12
    • 2012-02-25
    相关资源
    最近更新 更多