需要知道如何为 Xcode Objective C 实现此代码
Need to know how to implement this code for Xcode Objective C
我正在尝试根据当前位置、方位和距离获取 GPS 坐标。
我找到了这段代码:
- (double)degreesToRadians:(double)degrees {
return degrees * M_PI / 180;
}
- (double)radiansToDegrees:(double)radians {
return radians * 180/ M_PI;
}
- (CLLocationCoordinate2D)remoteCoordinate:(CLLocationCoordinate2D)localCoordinate withDistance:(double)distance withBearing:(double)bearing {
double earthRadius = 6378.1; // Radius of Earth in kilometres.
double rLat1 = [self degreesToRadians:localCoordinate.latitude]; // Convert latitude to radians
double rLon1 = [self degreesToRadians:localCoordinate.longitude]; // Convert longitude to radians
double rLat2 = asinl( sinl(rLat1) * cosl(distance / earthRadius) + cosl(rLat1) * sinl(distance / earthRadius) * cosl(bearing) );
double rLon2 = rLon1 + atan2l( sinl(bearing) * sinl(distance/earthRadius) * cosl(rLat1), cosl(distance/earthRadius) - sinl(rLat1) * sinl(rLat2) );
double dLat2 = [self radiansToDegrees:rLat2]; // Convert latitude to degrees
double dLon2 = [self radiansToDegrees:rLon2]; // Convert longuitude to degrees
return CLLocationCoordinate2DMake(dLat2, dLon2);
}
你好,我现在正在编写这个 iOS 程序,我想尝试你的代码,看看它是如何工作的,现在我该如何实现这个代码?我可以看到输入:
localCoordinate.latitude
localCoordinate.longitude
distance
bearing
输出:
dLat2
dLon2
我要启动流程吗?输入是 NSStrings 吗?
方位角 = [NSString stringWithFormat:@"%@.%@", deg1, min1]; // 度和分
intKiloMeters1 = [miles1 intValue] / 0.621371192;
NSLog(@"you get km %d", intKiloMeters1);
int distance;
distance = intKiloMeters1;
double bearing = [self degreesToRadians:[azimuth doubleValue]];
double earthRadius = 6378.1; // Radius of Earth in kilometres.
double rLat1 = [self degreesToRadians:myCoordinate.latitude]; // Convert latitude to radians
double rLon1 = [self degreesToRadians:myCoordinate.longitude]; // Convert longitude to radians
double rLat2 = asinl( sinl(rLat1) * cosl(distance / earthRadius) + cosl(rLat1) * sinl(distance / earthRadius) * cosl(bearing) );
double rLon2 = rLon1 + atan2l( sinl(bearing) * sinl(distance/earthRadius) * cosl(rLat1), cosl(distance/earthRadius) - sinl(rLat1) * sinl(rLat2) );
double finalLat1 = [self radiansToDegrees:rLat2]; // Convert latitude to degrees
double finalLong1 = [self radiansToDegrees:rLon2]; // Convert longuitude to degrees
NSLog(@"Export Lat %f Long %f", finalLat1, finalLong1);
CLLocationCoordinate2D unknownCoordinate = {finalLat1, finalLong1};
我正在尝试根据当前位置、方位和距离获取 GPS 坐标。
我找到了这段代码:
- (double)degreesToRadians:(double)degrees {
return degrees * M_PI / 180;
}
- (double)radiansToDegrees:(double)radians {
return radians * 180/ M_PI;
}
- (CLLocationCoordinate2D)remoteCoordinate:(CLLocationCoordinate2D)localCoordinate withDistance:(double)distance withBearing:(double)bearing {
double earthRadius = 6378.1; // Radius of Earth in kilometres.
double rLat1 = [self degreesToRadians:localCoordinate.latitude]; // Convert latitude to radians
double rLon1 = [self degreesToRadians:localCoordinate.longitude]; // Convert longitude to radians
double rLat2 = asinl( sinl(rLat1) * cosl(distance / earthRadius) + cosl(rLat1) * sinl(distance / earthRadius) * cosl(bearing) );
double rLon2 = rLon1 + atan2l( sinl(bearing) * sinl(distance/earthRadius) * cosl(rLat1), cosl(distance/earthRadius) - sinl(rLat1) * sinl(rLat2) );
double dLat2 = [self radiansToDegrees:rLat2]; // Convert latitude to degrees
double dLon2 = [self radiansToDegrees:rLon2]; // Convert longuitude to degrees
return CLLocationCoordinate2DMake(dLat2, dLon2);
}
你好,我现在正在编写这个 iOS 程序,我想尝试你的代码,看看它是如何工作的,现在我该如何实现这个代码?我可以看到输入:
localCoordinate.latitude
localCoordinate.longitude
distance
bearing
输出:
dLat2
dLon2
我要启动流程吗?输入是 NSStrings 吗?
方位角 = [NSString stringWithFormat:@"%@.%@", deg1, min1]; // 度和分
intKiloMeters1 = [miles1 intValue] / 0.621371192;
NSLog(@"you get km %d", intKiloMeters1);
int distance;
distance = intKiloMeters1;
double bearing = [self degreesToRadians:[azimuth doubleValue]];
double earthRadius = 6378.1; // Radius of Earth in kilometres.
double rLat1 = [self degreesToRadians:myCoordinate.latitude]; // Convert latitude to radians
double rLon1 = [self degreesToRadians:myCoordinate.longitude]; // Convert longitude to radians
double rLat2 = asinl( sinl(rLat1) * cosl(distance / earthRadius) + cosl(rLat1) * sinl(distance / earthRadius) * cosl(bearing) );
double rLon2 = rLon1 + atan2l( sinl(bearing) * sinl(distance/earthRadius) * cosl(rLat1), cosl(distance/earthRadius) - sinl(rLat1) * sinl(rLat2) );
double finalLat1 = [self radiansToDegrees:rLat2]; // Convert latitude to degrees
double finalLong1 = [self radiansToDegrees:rLon2]; // Convert longuitude to degrees
NSLog(@"Export Lat %f Long %f", finalLat1, finalLong1);
CLLocationCoordinate2D unknownCoordinate = {finalLat1, finalLong1};