我正在使用 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
.
另外,请检查 timestamp
和horizontalAccuracy
CLLocation
的交付给 locationManager:didUpdateToLocation:fromLocation:
的对象。如果位置测量结果看起来比您想要的更旧或不太准确,请设置一个计时器并等待发送更多位置测量结果。核心位置通常会快速提供缓存和/或不精确的位置,然后进行更准确的精细位置测量。
关于iphone - 如何使用 iPhone CLLocationManager 获取精确坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8401434/