iOS: How to convert MKMapPoint or CLLocationCoordinate2D to UTM?

人盡茶涼 提交于 2019-12-10 09:19:15

问题


From what I have read this takes some complicated Math that I am not good at. So, I am asking here.

Does anyone have experience converting a MKMapPoint or CLLocationCoordinate2D to a UTM value? I found this resource (http://www.uwgb.edu/dutchs/usefuldata/UTMFormulas.HTM) but the math is overwhelming.


回答1:


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.




回答2:


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.




回答3:


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

  • Objective C: https://github.com/jdp-global/MKMapViewZoom/blob/master/MKMapView%2BZoomLevel.m
  • for RubyMotion: http://rubydoc.info/gems/map-kit-wrapper/0.0.5/frames

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.



来源:https://stackoverflow.com/questions/4219775/ios-how-to-convert-mkmappoint-or-cllocationcoordinate2d-to-utm

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