MKCoordinateRegionMakeWithDistance的反向功能? [英] Reverse function of MKCoordinateRegionMakeWithDistance?
问题描述
MapKit的内置函数MKCoordinateRegionMakeWithDistance
以米为单位将距离转换为MKCoordinateRegion
:
MapKit's built in function MKCoordinateRegionMakeWithDistance
takes distances in meters and turns them into a MKCoordinateRegion
:
func MKCoordinateRegionMakeWithDistance(
_ centerCoordinate: CLLocationCoordinate2D,
_ latitudinalMeters: CLLocationDistance,
_ longitudinalMeters: CLLocationDistance)
-> MKCoordinateRegion
是否有一个倒数功能需要一个MKCoordinateRegion
并给我纬度和经度?
is there a reverse function that takes a MKCoordinateRegion
and gives me latitudinalMeters and longitudinalMeters?
推荐答案
MKCoordinateRegion
给出中心(纬度和经度)和跨度(delta纬度和经度).给定这些值,您可以确定纬度和经度区域边缘的位置.完成此操作后,您可以使用Haversine公式获取纬向和纵向距离,并且您已经知道中心.实际上,CLLocation
具有函数distanceFromLocation:(const CLLocation *)location
,应使用该函数避免直接执行该公式.
MKCoordinateRegion
gives a center (latitude and longitude) and span (delta latitude and longitude). Given these values, you can determine the location of the edges of the region in latitude and longitude. Once you do that, you can use the haversine formula to obtain latitudinal and longitudinal distances, and you already know the center. In fact, CLLocation
has a function distanceFromLocation:(const CLLocation *)location
which you should use to avoid a direct implementation of the formula.
这篇关于MKCoordinateRegionMakeWithDistance的反向功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!