iOS: How to convert MKMapPoint or CLLocationCoordinate2D to UTM?

亡梦爱人 提交于 2019-12-05 17:06:04

You could use one lib to do that, or analyze the code of one lib to understand the algorithm and do it yourself.

This is a c++ lib that does the job: http://geographiclib.sourceforge.net/html/

http://geographiclib.sourceforge.net/html/classGeographicLib_1_1UTMUPS.html

I found this website (http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html). If you look at the source code, the whole conversion is done using JavaScript, you can have a look at it and try to convert to Obj-c.

I recently wrote a class for this and posted a sample project on GitHub

UTMConverter example for iOS

The part you want is a file called UTMConverter.m. It has methods for converting from lat/long to UTM and vice-versa.

MKMapViewZoom appears to have some class methods which can convert between flat-map (geometric) & curved-map (geographic) coordinates, though I haven't tested them out. Somebody give me a thumbs up if this actually works

//convert from WGS84 (geographic coordinates) to UTM (geometric coordinates)
+ (double)longitudeToPixelSpaceX(double)pixelX
+ (double)latitudeToPixelSpaceY(double)pixelY

//convert from UTM to WGS84
+ (double)pixelSpaceXToLongitude(double)longitude
+ (double)pixelSpaceYToLatitude(double)latitude

some documentation here

UPDATE:

This is maddening, but in order to get this class's source code to work accurately I basically had to extract the methods into my own domain essentially, then remove the parts of the code referencing MERCATOR_OFFSET & change MERCATOR_RADIUS to the meters value of the Earth's radius. I was kind of, ok, very surprised when I discovered this actually worked.

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