我是客观的新手。我的程序是当按下开始按钮时,位置坐标应该开始跟踪并且应该同时跟踪距离,当按下停止按钮时,跟踪应该停止并且应该显示距离。
答案 0 :(得分:0)
假设您已经添加了必要的框架和委托,创建了对象 CLLocationManager * locationManager; 并完成了所有初始化
当您点击开始按钮时,请在 button_clicked 方法中调用此方法
[self.locationManager startUpdatingLocation];
点击停止按钮时,请调用此
[self.locationManager stopUpdatingLocation];
当您的位置更新后,将自动调用此委托方法,您可以在其中访问新的位置坐标
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
答案 1 :(得分:0)
CLLocationManagerDelegate在您确认委托后将委托设置为self时有助于实现此目的。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
每次将您的位置更改为回调函数时,都会调用此方法。
这是一个小教程,可能会为您提供一步一步的指导: http://www.mobisoftinfotech.com/blog/iphone/1474/
我希望它可以帮到你。 干杯!!