当我需要制作一个MKCoordinateRegion时,我执行以下操作:
var region = MKCoordinateRegion
.FromDistance(coordinate, RegionSizeInMeters, RegionSizeInMeters);很简单-效果很好。
现在我想存储当前区域跨度的值。当我查看region.Span值时,它是一个具有两个属性的MKCoordinateSpan:
public double LatitudeDelta;
public double LongitudeDelta;如何将LatitudeDelta值转换为latitudinalMeters?(因此,我可以使用上述方法重新创建我的区域(稍后)。
发布于 2014-01-22 06:10:41
如我所见,你已经有了地图的区域。它不仅包含拉特-长三角,而且是该区域的中心点。如图所示,您可以计算出以米为单位的距离:

1:获得区域跨度(该区域在拉特角/长度上有多大)
MKCoordinateSpan span = region.span;
2:获取区域中心(lat/长坐标)
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,西-东),并计算之间的距离(以米为单位)。
//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];发布于 2016-01-11 14:45:56
Hanne解决方案的快速实现:
let span = mapView.region.span
let center = mapView.region.center
let loc1 = CLLocation(latitude: center.latitude - span.latitudeDelta * 0.5, longitude: center.longitude)
let loc2 = CLLocation(latitude: center.latitude + span.latitudeDelta * 0.5, longitude: center.longitude)
let loc3 = CLLocation(latitude: center.latitude, longitude: center.longitude - span.longitudeDelta * 0.5)
let loc4 = CLLocation(latitude: center.latitude, longitude: center.longitude + span.longitudeDelta * 0.5)
let metersInLatitude = loc1.distanceFromLocation(loc2)
let metersInLongitude = loc3.distanceFromLocation(loc4)编辑:
对于Swift 5,distanceFromLocation(_:)已被重命名为distance(from:),这意味着最后两行现在改为
let metersInLatitude = loc1.distance(from: loc2)
let metersInLongitude = loc3.distance(from: loc4)发布于 2021-09-10 00:25:01
基于上述,下面是我在映射项目中使用的一个有用的扩展:
extension MKCoordinateRegion {
public var radius: CLLocationDistance {
let loc1 = CLLocation(latitude: center.latitude - span.latitudeDelta * 0.5, longitude: center.longitude)
let loc2 = CLLocation(latitude: center.latitude + span.latitudeDelta * 0.5, longitude: center.longitude)
let loc3 = CLLocation(latitude: center.latitude, longitude: center.longitude - span.longitudeDelta * 0.5)
let loc4 = CLLocation(latitude: center.latitude, longitude: center.longitude + span.longitudeDelta * 0.5)
let metersInLatitude = loc1.distance(from: loc2)
let metersInLongitude = loc3.distance(from: loc4)
let radius = max(metersInLatitude, metersInLongitude) / 2.0
return radius
}
}https://stackoverflow.com/questions/21273269
复制相似问题