gpt4 book ai didi

ios - 经度和纬度均为0.000000,为什么?

转载 作者:行者123 更新时间:2023-12-01 19:27:44 26 4
gpt4 key购买 nike

我使用核心位置获取当前位置的经度和纬度值,并且已将其显示在标签中,因此就我而言,经度和纬度均始终为0.000000,是因为我在模拟器上工作?

    //longitude and latitude
// locationManager update as location
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];

CLLocation *location = [locationManager location];

// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];

NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];

最佳答案

只是初始化,位置管理器不会获取您的值。

你必须写这个

[self.locationManager startUpdatingLocation];

那么你必须重写一个回调方法
- (void) locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation {


[self.locationManager stopUpdatingLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", newLocation.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", newLocation.longitude];
[self.locationManager release];
}

希望有帮助!
  • Shuanak
  • 关于ios - 经度和纬度均为0.000000,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5838029/

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