objective-c - MKMetersPerMapPointAtLatitude 背后的数学

标签 objective-c math map-projections apple-maps

我正在尝试将一些 Apple 映射代码转换为 Java。除了对 MKMetersPerMapPointAtLatitude

的几次调用外,我大部分都已正确转换

我有一个非常接近的解决方案...但它并不准确,我不确定为什么不。有什么想法吗?

#import <Foundation/Foundation.h>
#import <Math.h>
@import MapKit;

#define MERCATOR_OFFSET 268435456.0 / 2.0
#define MERCATOR_RADIUS (MERCATOR_OFFSET/M_PI)
#define WGS84_RADIUS 6378137.0
#define POINTS_PER_METER (MERCATOR_RADIUS / WGS84_RADIUS)

double MyMetersPerMapPointAtLatitude(double latitude) {
    return 1.0 / (POINTS_PER_METER / cos(latitude * M_PI / 180.0));
}

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        double latitude = 33.861315;
        for (int i = 0; i < 100; i++) {
            double a = MKMetersPerMapPointAtLatitude(latitude);
            double b = MyMetersPerMapPointAtLatitude(latitude);

            NSLog(@"%f %f", a, b);
            latitude += .1;
        }
    }
    return 0;
}

打印出以下内容

2015-05-19 09:13:00.334 Test[92619:5369062] 0.123522 0.123969
2015-05-19 09:13:00.335 Test[92619:5369062] 0.123379 0.123824
2015-05-19 09:13:00.335 Test[92619:5369062] 0.123236 0.123678
2015-05-19 09:13:00.335 Test[92619:5369062] 0.123092 0.123532
2015-05-19 09:13:00.335 Test[92619:5369062] 0.122948 0.123386
2015-05-19 09:13:00.335 Test[92619:5369062] 0.122804 0.123239
2015-05-19 09:13:00.335 Test[92619:5369062] 0.122659 0.123092
...etc

最佳答案

对于初学者,我们可以重新安排您的函数以使其更具可读性:

double MyMetersPerMapPointAtLatitude(double latitude) {
    return cos(latitude * M_PI / 180.0) / POINTS_PER_METER;
}

现在的问题是,正如 Tommy 所指出的,您没有考虑到地球变平的原因。你可以这样做:

double f = 1/298.257223563; // WGS84 flattening
double MyMetersPerMapPointAtLatitude(double latitude) {
    return (1-f) * cos(latitude * M_PI / 180.0) / POINTS_PER_METER;
}

这将错误降低到我将其归因于舍入和截断的程度。

关于objective-c - MKMetersPerMapPointAtLatitude 背后的数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30326797/

相关文章:

python - 如何在没有 SymPy 的情况下计算给定函数的积分?

maps - 将纬度/经度转换为地理引用 map 上的相对 X/Y 坐标

objective-c - 无法追踪的奇怪 GDB 错误

linux - 如何将带点的版本号转换为整数?

ios - Pod install 在安装期间导致 "Using Google-Mobile-Ads-SDK"但文件不存在

JavaScript 数学 — 得到错误答案 (128 - 64 = -64)?

google-maps - 计算静态谷歌地图图像的边界框

math - 查看等距柱状图

ios - 原子性质和用途

ios - 从数组中删除重复的项目并保留最后出现的项目 - iOS