gpt4 book ai didi

ios - 尝试获取 iOS MKCoordinateSpan 的跨度大小(以米为单位)

转载 作者:技术小花猫 更新时间:2023-10-29 10:41:26 30 4
gpt4 key购买 nike

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

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

非常简单 - 完美运行。

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

public double LatitudeDelta;
public double LongitudeDelta;

请问如何将 LatitudeDelta 值转换为 latitudinalMeters? (这样我就可以(稍后)使用上述方法重新创建我的区域...

最佳答案

正如我所看到的,您已经有了 map 的区域。它不仅包含纬度和经度三角洲,还包含该区域的中心点。您可以如图所示以米为单位计算距离:

enter image description here

1:获取区域跨度(区域有多大,以纬度/经度表示)

MKCoordinateSpan span = region.span;

2:获取区域中心(lat/long坐标)

CLLocationCoordinate2D center = region.center;

3:根据中心位置创建两个位置(loc1 & loc2,南北)并计算它们之间的距离(以米为单位)

//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)并计算它们之间的距离(以米为单位)

//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 - 尝试获取 iOS MKCoordinateSpan 的跨度大小(以米为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21273269/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com