【发布时间】: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