MKCoordinateSpan 以米为单位?

发布于 2024-12-04 05:08:37 字数 155 浏览 1 评论 0原文

我需要创建一个大约 500 米的 MKCooperativeSpan

如何计算要传递到 MKCooperativeSpan 构造函数中的值?

任何编程(Obj-C、.Net)语言的答案都可以。

I need to create a MKCoordinateSpan that is about 500 meters.

How do I calculate the values to pass into the MKCoordinateSpan constructor?

Answers in any programming (Obj-C, .Net) language are fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘逸的'云 2024-12-11 05:08:37

另一种替代方法是使用 MapKit 的 MKCooperativeRegionMakeWithDistance 函数:

MKCoordinateRegion rgn = MKCoordinateRegionMakeWithDistance(
    CLLocationCoordinate2DMake(someLatitude, someLongitude), 500, 500);

MKCooperativeSpan 将位于 rgn.span 中。

Another alternative is to use MapKit's MKCoordinateRegionMakeWithDistance function:

MKCoordinateRegion rgn = MKCoordinateRegionMakeWithDistance(
    CLLocationCoordinate2DMake(someLatitude, someLongitude), 500, 500);

The MKCoordinateSpan will be in rgn.span.

赏烟花じ飞满天 2024-12-11 05:08:37

除非您需要很高的精度,否则可以使用近似值使其变得更容易。第一个问题是找出代表 500 米的纬度的分数。很容易,因为纬度在任何位置都是一个常数,大约为 111 公里。所以 500 米是纬度 0.0045 度。

然后它会变得更加困难,因为经度的长度根据你所在的位置而变化。 进行近似

它可以用在此处输入图像描述

,其中 alpha 是地球赤道半径,6,378,137km,b/a 是 0.99664719 (a用于所有 GPS 设备使用的 WGC84 球体模型的常数)和 在此处输入图像描述 其中 phi 是纬度。

想象一下,您很幸运地身处南经 37.783 度的墨尔本。在这里,南北经并不重要。 beta 的计算结果为 37.6899,其余部分解出长度为 88 公里的经度。所以 500 米是 0.0057 度。

墨尔本的结果 - MKCooperativeSpan melbourne500MeterSpan = MKCooperativeSpanMake(.0045, .0057);

您可以检查您的答案和代码 使用此在线计算器

关于经度的维基文章对此有更多详细信息(并且它是此处图像的来源)

代码:

#define EARTH_EQUATORIAL_RADIUS (6378137.0)
#define WGS84_CONSTANT (0.99664719)

#define degreesToRadians(x) (M_PI * (x) / 180.0)

// accepts decimal degrees. Convert from HMS first if that's what you have
double spanOfMetersAtDegreeLongitude(double degrees, double meters) {

    double tanDegrees = tanf(degreesToRadians(degrees));
    double beta =  tanDegrees * WGS84_CONSTANT;
    double lengthOfDegree = cos(atan(beta)) * EARTH_EQUATORIAL_RADIUS * M_PI / 180.0;
    double measuresInDegreeLength = lengthOfDegree / meters;
    return 1.0 / measuresInDegreeLength;
}

Unless you need great accuracy you can make it much easier with approximation. The first problem is to find the fraction of a degree of latitude representing 500 meters. Easy since a degree of latitude is a constant in any location, roughly 111 km. So 500 meters is .0045 degrees latitude.

Then it gets harder because length of a degree of longitude varies depending on where you are. It can be approximated with

enter image description here

where alpha is earth's equatorial radius, 6,378,137km, b/a is 0.99664719 (a constant in use for the WGC84 spheroid model in use by all GPS devices) and enter image description here where phi is the degree of latitude.

Imagine for a second you're lucky enough to be in Melbourne with a longitude of 37.783 degrees S. North or South doesn't matter here. beta works out to be 37.6899 and the rest of it solves to give a longitudinal degree a length of 88km. So 500 meters is .0057 of a degree.

Result for Melbourne - MKCoordinateSpan melbourne500MeterSpan = MKCoordinateSpanMake(.0045, .0057);

You can check your answers and your code with this online calculator

The wiki article on longitude has a lot more detail on this (and it the source of the images here)

Code:

#define EARTH_EQUATORIAL_RADIUS (6378137.0)
#define WGS84_CONSTANT (0.99664719)

#define degreesToRadians(x) (M_PI * (x) / 180.0)

// accepts decimal degrees. Convert from HMS first if that's what you have
double spanOfMetersAtDegreeLongitude(double degrees, double meters) {

    double tanDegrees = tanf(degreesToRadians(degrees));
    double beta =  tanDegrees * WGS84_CONSTANT;
    double lengthOfDegree = cos(atan(beta)) * EARTH_EQUATORIAL_RADIUS * M_PI / 180.0;
    double measuresInDegreeLength = lengthOfDegree / meters;
    return 1.0 / measuresInDegreeLength;
}
放我走吧 2024-12-11 05:08:37

在 MonoTouch 中,然后使用此解决方案,您可以使用此辅助方法:

    public static void ZoomToCoordinateAndCenter (MKMapView mapView, CLLocationCoordinate2D coordinate, double meters, bool showUserLocationToo, bool animate)
    {
        if (!coordinate.IsValid ())
            return;

        mapView.SetCenterCoordinate (coordinate, animate);
        mapView.SetRegion (MKCoordinateRegion.FromDistance (coordinate, meters, meters), animate);      
    }

In MonoTouch, then using this solution you can use this helper method:

    public static void ZoomToCoordinateAndCenter (MKMapView mapView, CLLocationCoordinate2D coordinate, double meters, bool showUserLocationToo, bool animate)
    {
        if (!coordinate.IsValid ())
            return;

        mapView.SetCenterCoordinate (coordinate, animate);
        mapView.SetRegion (MKCoordinateRegion.FromDistance (coordinate, meters, meters), animate);      
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文