Ios5 iOS 5返回错误的用户位置,而iOS 4不返回';T
我有3台iPad: iPad 3G/WiFi iOS 5.0.1 iPad2 3G/WiFi iOS 4.3.5 iPad 2 WiFi iOS 5.0.1 在所有3台iPad上运行相同的代码会导致我的位置在运行iOS 5.0.1的iPad上被报告为“纽约市”,而运行iOS 4.3.5的iPad会返回我的正确位置 原因可能是什么 谢谢 新增代码:Ios5 iOS 5返回错误的用户位置,而iOS 4不返回';T,ios5,Ios5,我有3台iPad: iPad 3G/WiFi iOS 5.0.1 iPad2 3G/WiFi iOS 4.3.5 iPad 2 WiFi iOS 5.0.1 在所有3台iPad上运行相同的代码会导致我的位置在运行iOS 5.0.1的iPad上被报告为“纽约市”,而运行iOS 4.3.5的iPad会返回我的正确位置 原因可能是什么 谢谢 新增代码: // AppDelegate.h // Created by Michael Superczynski on 8/27/11. // Copyr
// AppDelegate.h
// Created by Michael Superczynski on 8/27/11.
// Copyright 2011 HyperNova Software. All rights reserved.
#import "Locator.h"
#import <UIKit/UIKit.h>
@interface AppDelegate : NSObject <UIApplicationDelegate>
{
CLLocationManager *locationManager;
Locator *locator;
}
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) Locator *locator;
@end
// AppDelegate.m
// Created by Michael Superczynski on 8/27/11.
// Copyright 2011 HyperNova Software. All rights reserved.
#import "AppDelegate.h"
#import "Locator.h"
#import <MapKit/MapKit.h>
@implementation AppDelegate
@synthesize locationManager;
@synthesize locator;
. . .
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Locator *aLocator = [[Locator alloc]init];
locator = aLocator;
CLLocationManager *aLocationManager = [[CLLocationManager alloc] init];
locationManager = aLocationManager;
locationManager.delegate = locator;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 100;
locationManager.purpose = @"This will show your location on the map";
[locator startStandardUpdates];
. . .
}
//
// Locator.h
//
// Created by Michael Superczynski on 8/30/11.
// Copyright 2011 HyperNova Software. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface Locator : NSObject <CLLocationManagerDelegate, MKReverseGeocoderDelegate>
{
NSString *currentLocation;
CLLocation *currentCLLocation;
CLLocationManager *locationManager;
}
@property (nonatomic, strong) NSString *currentLocation;
@property (nonatomic, strong) CLLocation *currentCLLocation;
@property (nonatomic, strong) CLLocationManager *locationManager;
-(void)reverseGeocodeCurrentLocation:(CLLocation *)location;
-(void)startStandardUpdates;
@end
//
// Locator.m
//
// Created by Michael Superczynski on 8/30/11.
// Copyright 2011 HyperNova Software. All rights reserved.
//
#import "AppDelegate.h"
#import <CoreLocation/CoreLocation.h>
#import "Locator.h"
@implementation Locator
@synthesize currentLocation;
@synthesize currentCLLocation;
@synthesize locationManager;
-(id)init
{
self = [super init];
if (self)
{
// Initialization code here.
}
return self;
}
-(void)startStandardUpdates
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[CLLocationManager locationServicesEnabled];
currentCLLocation = [[CLLocation alloc]init];
[locationManager startUpdatingLocation];
float latitude;
float longitude;
if (![CLLocationManager locationServicesEnabled])
{
latitude = kDefaultLocationLatitudeA;
longitude = kDefaultLocationLongitudeA;
}
else
{
latitude = (float)locationManager.location.coordinate.latitude;
longitude = (float)locationManager.location.coordinate.longitude;
}
CLLocation *location = [[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
[self reverseGeocodeCurrentLocation:location];
}
// Delegate method from the CLLocationManagerDelegate protocol.
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSDate* eventDate = newLocation.timestamp;
currentCLLocation = newLocation;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
newLocation.coordinate.latitude,
newLocation.coordinate.longitude] argument:nil];
// If it's a relatively recent event, turn off updates to save power
if ((abs((int)(howRecent))) < 30.0)
[self reverseGeocodeCurrentLocation:newLocation];
}
-(void)reverseGeocodeCurrentLocation:(CLLocation *)location
{
MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc]initWithCoordinate:location.coordinate];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
self.currentLocation = [NSString stringWithFormat:@"%@, %@", placemark.administrativeArea, placemark.country];
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
if ([error code] != kCLErrorLocationUnknown)
[locationManager stopUpdatingLocation];
float latitude = kDefaultLocationLatitudeA;
float longitude = kDefaultLocationLongitudeA;
CLLocation *cLLocation = [[CLLocation alloc]initWithLatitude:latitude longitude:longitude];
}
-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
if ([error code] != kCLErrorLocationUnknown)
[locationManager stopUpdatingLocation];
}
@end
//AppDelegate.h
//由Michael Superczynski于2011年8月27日创建。
//版权所有2011 HyperNova软件。版权所有。
#导入“Locator.h”
#进口
@接口AppDelegate:NSObject
{
CLLocationManager*locationManager;
定位器*定位器;
}
@属性(非原子,强)CLLocationManager*locationManager;
@属性(非原子,强)定位器*定位器;
@结束
//AppDelegate.m
//由Michael Superczynski于2011年8月27日创建。
//版权所有2011 HyperNova软件。版权所有。
#导入“AppDelegate.h”
#导入“Locator.h”
#进口
@实现AppDelegate
@综合定位经理;
@综合定位器;
. . .
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
定位器*aLocator=[[Locator alloc]init];
定位器=aLocator;
CLLocationManager*aLocationManager=[[CLLocationManager alloc]init];
位置管理器=位置管理器;
locationManager.delegate=定位器;
locationManager.desiredAccuracy=KCallocationAccuracykilometer;
locationManager.distanceFilter=100;
locationManager.purpose=@“这将在地图上显示您的位置”;
[定位器开始标准更新];
. . .
}
//
//定位器
//
//由Michael Superczynski于2011年8月30日创建。
//版权所有2011 HyperNova软件。版权所有。
//
#进口
#进口
@接口定位器:NSObject
{
NSString*当前位置;
CLLocation*当前CLLocation;
CLLocationManager*locationManager;
}
@属性(非原子,强)NSString*currentLocation;
@属性(非原子,强)CLLocation*currentCLLocation;
@属性(非原子,强)CLLocationManager*locationManager;
-(void)reverseGeocodeCurrentLocation:(CLLocation*)位置;
-(无效)开始和结束更新;
@结束
//
//定位器
//
//由Michael Superczynski于2011年8月30日创建。
//版权所有2011 HyperNova软件。版权所有。
//
#导入“AppDelegate.h”
#进口
#导入“Locator.h”
@实现定位器
@综合当前位置;
@综合定位;
@综合定位经理;
-(id)init
{
self=[super init];
如果(自我)
{
//这里是初始化代码。
}
回归自我;
}
-(无效)开始和结束更新
{
AppDelegate*AppDelegate=(AppDelegate*)[[UIApplication sharedApplication]委托];
[CLLocationManager LocationServiceEnabled];
currentCLLocation=[[CLLocation alloc]init];
[locationManager startUpdatingLocation];
浮动纬度;
浮动经度;
如果(![CLLocationManager位置服务启用])
{
纬度=kDefaultLocationLatitudeA;
经度=kDefaultLocationLongitudeA;
}
其他的
{
纬度=(浮点)locationManager.location.coordinate.latitude;
经度=(float)locationManager.location.coordinate.longitude;
}
CLLocation*location=[[CLLocation alloc]initWithLatitude:纬度经度:经度];
[自反转eCoodecurrentLocation:位置];
}
//CLLocationManagerDelegate协议中的委托方法。
-(无效)locationManager:(CLLocationManager*)经理
DidUpdateLocation:(CLLocation*)newLocation
fromLocation:(CLLocation*)oldLocation
{
NSDate*eventDate=newLocation.timestamp;
currentCLLocation=新位置;
NSTimeInterval howRecent=[eventDate timeIntervalSinceNow];
newLocation.coordinate.latitude,
newLocation.coordinate.longitude]参数:nil];
//如果是相对较新的事件,请关闭更新以节省电源
如果((abs((int)(最近))<30.0)
[self reverseGeocodeCurrentLocation:newLocation];
}
-(无效)reverseGeocodeCurrentLocation:(CLLocation*)位置
{
MKReverseGeocoder*reverseGeocoder=[[MKReverseGeocoder alloc]initWithCoordinate:location.coordinate];
reverseGeocoder.delegate=self;
[反向编码器启动];
}
-(无效)反向编码器:(MKReverseGeocoder*)地理编码器未找到位置标记:(MKPlacemark*)位置标记
{
self.currentLocation=[NSString stringWithFormat:@“%@,%@”,placemark.administrativeArea,placemark.country];
}
-(void)reverseGeocoder:(MKReverseGeocoder*)地理编码器错误:(NSError*)错误
{
如果([错误代码]!=kCLErrorLocationUnknown)
[locationManager停止更新位置];
浮动纬度=kDefaultLocationLatitudeA;
浮动经度=kDefaultLocationLongitudeA;
CLLocation*CLLocation=[[CLLocation alloc]initWithLatitude:纬度经度:经度];
}
-(void)reverseGeocoder:(MKReverseGeocoder*)地理编码器监控DIDFailforRegion:(CLRegion*)region withError:(NSError*)错误
{
如果([错误代码]!=kCLErrorLocationUnknown)
[locationManager停止更新位置];
}
@结束