What is the difference between MKCoordinateSpan and CLLocationCoordinate2D

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 08:53:12

问题


I was going through the sample example of MapKit and CoreLocation framework. I found these two structs (MKCoordinateSpan and CLLocationCoordinate2D) which are similar in declaration. How are these different in functionality, can someone please site an example (using both) to clear their meanings.

Thanks!


回答1:


MKCoordinateSpan defines a span, i.e. a delta, in the latitude and longitude directions to show on a map. Along with a point you can then define a region to display on a map.

CLLocationCoordinate2D defines a single point in the latitude and longitude coordinate system.

For example:

|<---- deltaLat  ---->|
|---------------------|---
|                     | |
|                     | |
|                     | |
|                     | |
|          +          |deltaLon
|      (lat,lon)      | |
|                     | |
|                     | |
|                     | |
|---------------------|---

Here you can imagine a centre point (lat,lon) about which you have a deltaLat and a deltaLon.

So (lat,lon) would be a CLLocationCoordinate2D and deltaLat, deltaLon would form a MKCoordinateSpan.

You're right that both structures are defined in the same way, but this is quite common where the two different structures have different semantics and therefore are defined separately like you've found.




回答2:


MKCoordinateSpan is interpreted as delta values, whereas CLLocationCoordinate2D is interpreted as a point.

For example, let's say you want to define a circular region, you would define a center point, and the radius around it.

In MapKit, you define a rectangular region by MKCoordinateRegion. The center point is a CLLocationCoordinate2D (latitude and longitude - both typedef of double) and a vertical and horizontal delta by MKCoordinateSpan (latitudeDelta and longitudeDelta - both typedef of double)



来源:https://stackoverflow.com/questions/9771435/what-is-the-difference-between-mkcoordinatespan-and-cllocationcoordinate2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!