尝试获取iOS MKCoordinateSpan的跨度大小(以米为单位) [英] Trying to get the span size in meters for an iOS MKCoordinateSpan

查看:1978
本文介绍了尝试获取iOS MKCoordinateSpan的跨度大小(以米为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我需要制作 MKCoordinateRegion 时,我会执行以下操作:

When I need to make an MKCoordinateRegion, I do the following:

var region = MKCoordinateRegion
               .FromDistance(coordinate, RegionSizeInMeters, RegionSizeInMeters);

非常简单 - 效果很好。

very simple - works perfectly.

现在我希望存储当前区域 span 的值。当我查看 region.Span 值时,它是一个 MKCoordinateSpan ,它有两个属性:

Now I wish to store the value of the current region span. When i look at the region.Span value, it’s an MKCoordinateSpan which has two properties:

public double LatitudeDelta;
public double LongitudeDelta;

如何将 LatitudeDelta 值转换为a latitudinalMeters 好吗? (那么我可以使用上面的方法重新创建我的区域(稍后)...

How can I convert the LatitudeDelta value into a latitudinalMeters please? (So then I can recreate my region (later on) using the above method...

推荐答案

我已经看到你了拥有地图的区域。它不仅包含纬度和长度增量,还包含区域的中心点。您可以计算距离(以米为单位),如图所示:

As I can see you already have the region of the map. It doesn't only contain the lat & long deltas but also the center point of the region. You can calculate the distances in meters as illustrated in the picture:

1:获取区域跨度(区域在纬度/长度上有多大)

1: Get the region span (how big the region is in lat/long degrees)

MKCoordinateSpan span = region.span;

2:获取区域中心(纬度/经度坐标)

2: Get the region center (lat/long coordinates)

CLLocationCoordinate2D loc = region.center;

3:根据中心创建两个位置(loc1& loc2,north-south)位置并计算其间的距离(以米为单位)

3: Create two locations (loc1 & loc2, north - south) based on the center location and calculate the distance inbetween (in meters)

//get latitude in meters
CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:(center.latitude - span.latitudeDelta * 0.5) longitude:center.longitude];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:(center.latitude + span.latitudeDelta * 0.5) longitude:center.longitude];
int metersLatitude = [loc1 distanceFromLocation:loc2];

4:根据中心位置创建两个位置(loc3& loc4,west-east)计算中间距离(以米为单位)

4: Create two locations (loc3 & loc4, west - east) based on the center location and calculate the distance inbetween (in meters)

//get longitude in meters
CLLocation *loc3 = [[CLLocation alloc] initWithLatitude:center.latitude longitude:(center.longitude - span.longitudeDelta * 0.5)];
CLLocation *loc4 = [[CLLocation alloc] initWithLatitude:center.latitude longitude:(center.longitude + span.longitudeDelta * 0.5)];
int metersLongitude = [loc3 distanceFromLocation:loc4];

这篇关于尝试获取iOS MKCoordinateSpan的跨度大小(以米为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆