位置经理提供非常糟糕的坐标

时间:2013-06-21 11:18:52

标签: gps location cllocationmanager core

我尝试使用Core Location编写一个坐标,它运行得很好,唯一的问题是,它在坐标方面是一种植物。

这是获取坐标的代码。

- (void)viewDidLoad
{
[super viewDidLoad];

self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
{
if (startingLocation == nil)
    self.startingLocation = newLocation;
NSString *latitudeString  = [[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.latitude];
latitudeLabel.text = latitudeString;

NSString *longitudeString = [[NSString alloc] initWithFormat:@"%g",newLocation.coordinate.longitude];
longitudeLabel.text = longitudeString;

NSString *horizontalAccuracyString = [[NSString alloc] initWithFormat:@"%g",newLocation.horizontalAccuracy];
horizontalAccuraryLabel.text = horizontalAccuracyString;

NSString *altitudeString = [[NSString alloc] initWithFormat:@"%g",newLocation.altitude];
altitudeLabel.text = altitudeString;

NSString *verticalAccuracyString = [[NSString alloc] initWithFormat:@"%g",newLocation.verticalAccuracy];
verticalAccuracyLabel.text = verticalAccuracyString;

CLLocationDistance distance = [newLocation getDistanceFrom:startingLocation];
NSString *distanceString = [[NSString alloc] initWithFormat:@"%g",distance];
distanceTraveledLabel.text = distanceString;

}

它给了我Lat:37.7858 Long:-122.406这是在美国的某个地方,而我正在运行来自欧洲,罗马尼亚的代码......

可能是因为它是从模拟器运行的吗?

我也知道locationManager:didUpdateToLocation:fromLocation已被弃用,但我试过这样做:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

但我不知道如何访问[location lastObject]的元素。

1 个答案:

答案 0 :(得分:2)

那个lat&长期的组合是旧金山,这是许多通勤(通过豪华的通勤巴士)苹果员工的基地。

您可以非常轻松地设置模拟器的工作位置:

you can set your preferred location in the iPhone simulator

纬度&布加勒斯特的经度是“44.4325”& “26.103889”,据我所知。

至于访问“[location lastObject]”的元素,该数组中的对象将是具有“coordinate”属性的CLLocation object。如果您调用了“didUpdateLocations:”委托方法,该数组将始终至少有一个位置(您可以通过“lastObject”访问该位置。)