【发布时间】:2013-12-19 06:17:31
【问题描述】:
我只想在应用程序启动时获取用户当前位置(纬度,经度)..我不想使用委托方法进行频繁的位置更新..我不使用地图只需要启动时的当前位置..应该如何我这样做??
我正在使用下面的代码,但它不起作用。
CLLocationManager *locationManager;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location;
location = [locationManager location];
CLLocationCoordinate2D coord;
coord.longitude = location.coordinate.longitude;
coord.latitude = location.coordinate.latitude;
NSLog(@"latitude %f longitude %f",coord.latitude,coord.longitude);
输出:- 纬度 0.000000 经度 0.000000
请帮忙..
【问题讨论】:
-
嘿,你必须通过委托方法来获取用户的当前位置
-
获取位置后,您必须使用委托方法,您可以停止位置管理器的位置更新
-
[locationManager stopUpdatingLocation];
-
谢谢大家......使用委托方法获取位置,然后使用 [locationManager stopUpdatingLocation] 停止未来更新。
标签: ios mapkit core-location