gpt4 book ai didi

ios - 核心定位不断循环

转载 作者:行者123 更新时间:2023-11-28 20:24:28 25 4
gpt4 key购买 nike

我基本上是从这个 CoreLocation iOS 教程开始的,目的是了解如何在我的应用程序中实现 CoreLocation。 ( http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_Location_Application )

但我在尝试将本教程合并到我的应用程序时遇到的情况是,它现在一直在不断循环,这让我感到困惑。有人可以帮忙吗?

GPSViewController.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface GPSViewController : UIViewController
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong, nonatomic) CLLocation *startLocation;
@end

GPSViewController.m

#import "GPSViewController.h"

#import "DataClass.h"

@interface GPSViewController ()

@end

@implementation GPSViewController
@synthesize locationManager, startLocation;

DataClass *obj;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

//initialization og global varable.
DataClass *obj=[DataClass getInstance];

//GPS Initialise
self.locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
startLocation = nil;

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark CLLocationManagerDelegate

-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSString *currentLatitude = [[NSString alloc]
initWithFormat:@"%g",
newLocation.coordinate.latitude];
//latitude.text = currentLatitude;
obj.Latatude = currentLatitude;

NSString *currentLongitude = [[NSString alloc]
initWithFormat:@"%g",
newLocation.coordinate.longitude];
//longitude.text = currentLongitude;
obj.Longitude = currentLongitude;

NSLog(@"latitude %+.6f, longitude %+.6f\n",
newLocation.coordinate.latitude,
newLocation.coordinate.longitude);

if(obj.Latatude != NULL && obj.Longitude != NULL){
[self performSegueWithIdentifier:@"GPSSuccess" sender:self];
}
}

-(void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.startLocation = nil;
self.locationManager = nil;
}


@end

最佳答案

您应该调用 [locationManager stopUpdatingLocation]; 以阻止它反复获取用户的位置。

关于ios - 核心定位不断循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14493714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com