我想在應用程序啓動時獲取用戶當前位置(拉特,長)..我不想使用委託方法來頻繁位置更新..我不使用地圖只是需要啓動當前的位置..我應該怎麼做?如何讓用戶在應用程序啓動時的當前位置
我使用下面的代碼,但它不工作。
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
請幫助..
嘿你必須去槽代表方法來獲得當前位置的用戶 –
你必須使用委託medhods一旦位置被提取您可以停止位置管理器的位置更新 –
[locationManager stopUpdatingLocation]; –