在此代码中,我收到错误的距离,_latitude和_longitude是NSString。 有任何建议要纠正这个问题吗?
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coord;
coord.latitude = [_latitude doubleValue];
coord.longitude = [_longitude doubleValue];
CLLocation *anotLocation = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude];
_distancia = [NSNumber numberWithFloat:([location distanceFromLocation:anotLocation]/1000)];
答案 0 :(得分:0)
查看位置控制器的单例实现
https://github.com/hackerinheels/locationcontroller
只需拨打电话
CLLocation *currLocation = [[LocationController sharedLocationInterface]getCurrentLocation];