我正在使用CLLocationManager * locationManager和獲取座標,但這些座標不是精確的谷歌地圖座標。我如何獲得確切的座標使用iPhone CLLocationManager
iPhone座標以下 < + 26.86126232,+ 75.75962328> +/-100.00米(速度-1.00 MPS /當然-1.00)
谷歌地圖座標相同設備的位置處的座標以下 < + 26.860524,+ 75.761569>
谷歌地圖座標是正確的,但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
那麼你現在如何獲得座標?至少需要顯示一些代碼。 – Luke
- (void)viewDidLoad { \t \t locationController = [[MyCLController alloc] init]; \t locationController.delegate = self; [locationController.locationManager startUpdatingLocation]; } - (void)dealloc \t [locationController release]; [super dealloc]; } - (void)locationUpdate:(CLLocation *)location {location} {locationLabel.text = [location description]; } - (void)locationError:(NSError *)error {0} 0} locationLabel.text = [error description]; } – priya
在MyCLController類中,我定義了委託並創建了CLLocationManager * locationManager的對象。這個課程來自示例。 –
priya