我想在不使用地图的情况下获取当前位置的纬度和经度,是否可以这样做,我没有通过搜索互联网获得,任何人都可以帮我找到它。
我尝试使用核心位置,但即使我没有任何东西。 请告诉我如何找到纬度和经度,谢谢。
//remember to stop before you are done, either here or in view disappearance.
- (void) dealloc
{ [locationManager stopUpdatingLocation]; }
答案 0 :(得分:0)
:
CLLocationManager *locationMgr;
<。>在.m文件中:加载
locationMgr =[[CLLocationManager alloc] init];
locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
locationMgr.delegate = self;
if ([locationMgr respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationMgr requestWhenInUseAuthorization];
}
[locationMgr startUpdatingLocation];
添加以下代表:
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// Handle location updates
CLLocationCoordinate2D location=newLocation.coordinate;
float altitude = newLocation.altitude;
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
// Handle error
NSLog(@"error: %@",[error localizedDescription]);
}
您可能没有从用户那里授权该位置。这就是为什么你没有得到任何东西 感谢