我想在 iOS 中进行地理边界框计算。 它可以是大约。
输入参数:
当前位置(示例:41.145495、-73.994901)
以米为单位的半径:(示例:2000)
要求的输出:
MinLong:(示例:41.9995495)
MinLat:(示例:−74.004901)
MaxLong:(示例:41.0005495)
MaxLat:(示例:−73.004901)
要求: 无网络通话
有什么想法吗? Mapkit/CoreLocation 好像没有提供这种东西?
我可以使用任何其他地理 SDK 吗?
谢谢
最佳答案
我认为您可以使用标准的 MapKit 函数:MKCoordinateRegionMakeWithDistance , 这将返回 MKCoordinateRegion , 这实际上只是一个中心点 (lat, lon) 以及纬度和经度方向上的跨度(以度为单位)。分别从纬度和经度中添加/减去跨度的一半,您将获得所需的值。
CLLocationCoordinate2D centerCoord = CLLocationCoordinate2DMake(41.145495, −73.994901);
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(centerCoord, 2000, 2000);
double latMin = region.center.latitude - .5 * startRegion.span.latitudeDelta;
double latMax = region.center.latitude + .5 * startRegion.span.latitudeDelta;
double lonMin = region.center.longitude - .5 * startRegion.span.longitudeDelta;
double lonMax = region.center.longitude + .5 * startRegion.span.longitudeDelta;
顺便说一句:这仅代表小跨度的经度,大约几公里。至quote Apple :
latitudeDelta
The amount of north-to-south distance (measured in degrees) to use for the span. Unlike longitudinal distances, which vary based on the latitude, one degree of latitude is approximately 111 kilometers (69 miles) at all times.longitudeDelta
The amount of east-to-west distance (measured in degrees) to use for the span. The number of kilometers spanned by a longitude range varies based on the current latitude. For example, one degree of longitude spans a distance of approximately 111 kilometers (69 miles) at the equator but shrinks to 0 kilometers at the poles.
关于ios - 如何计算iOS中的地理边界框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12465711/