Difficulties understanding MapKit Coordinate System

梦想的初衷 提交于 2019-12-24 00:55:37

问题


I read the apple docs

"A map point is an x and y value on the Mercator map projection" A point is a graphical unit associated with the coordinate system of a UIView

What is the difference logically between a Point and a MKPoint? I obviously need CGPoint to display something on the screen. So why does MapKit need MKMapPoint?


回答1:


The fact that both the CGPoint and MKMapPoint structs happen to store two floating-point values named x and y is irrelevant.

They are given different names because they logically deal with different coordinate systems, transformations, ranges and scales.

A 2D world map needs a large, fixed coordinate system that allows a latitude and longitude to be converted to a fixed point on the map regardless of what portion is currently being displayed on the screen.

The range of MKMapPoint values are large since they need to represent the world's coordinates at a high-enough resolution (well beyond screen sizes).

However, you don't exactly need to care about the actual values of an MKMapPoint. Occasionally, you may need to convert a CLLocationCoordinate2D to an MKMapPoint (or the other way around) but you don't need to worry about those values nor should you store them (the docs recommend not doing this since the internal projection calculations to convert a latitude and longitude to a 2D projection may change between iOS releases).

Your usage of an MKMapPoint is only on the basis that you are dealing with the map's 2D projection independent of the device's screen size or what portion of the map is currently displaying.


I obviously need CGPoint to display something on the screen.

Yes but when adding annotations or overlays, you generally deal with CLLocationCoordinate2D values and let the map view do the conversion as needed.




回答2:


MKMapPoint is a geographical point - projectively converted latitude and longitude. On the screen you have some bounded view containing your mapView. And you need to convert your geographical position (coord) to the CGPoint on your mapView

CLLocationCoordinate2D coord;
coord.latitude = location.latitude.doubleValue;
coord.longitude = location.longitude.doubleValue;

MKMapPoint point = MKMapPointForCoordinate(coord);

CGPoint cgpoint = [mapView convertCoordinate:coord toPointToView:mapView];


来源:https://stackoverflow.com/questions/21094369/difficulties-understanding-mapkit-coordinate-system

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