我正努力获取当前位置的经度和纬度,并使用代码
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Latitude : %@",lat);
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
// longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
// degrees, minutes, seconds];
longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
NSLog(@" Current Longitude : %@",longt);
}
获得:
当前纬度:37°47'9.0024“ 经度:-122°24'23.1012“
但我希望纬度和经度像13.233233(平均值)。那么我如何在经度和纬度中转换这个呢?请帮助。
答案 0 :(得分:0)
为什么使用此折旧方法使用此方法在iOS 7中获取位置。使用此方法
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// location_updated = [locations lastObject];
// NSLog(@"updated coordinate are %@",location_updated);
float currentLocationLati = [[locations objectAtIndex:0] coordinate].latitude;
float currentLocationLong = [[locations objectAtIndex:0] coordinate].longitude;
}
通过这种方法,你会发现更新纬度和经度只是使用它们不要将它们转换为度
答案 1 :(得分:0)
从以下答案Converting from longitude\latitude to Cartesian coordinates
x = R * cos(lat) * cos(lon)
y = R * cos(lat) * sin(lon)
z = R *sin(lat)
其中R是近似的地球半径(例如6371KM)。
答案 2 :(得分:0)
在newLocation.coordinate.latitude和newLocation.coordinate.longitude中,您拥有所需的值,只是不要转换它们。