iphone — convert MKMapPoint distances to meters
Say I have a square which consists of four CLLocationCoordinate2D points, which are in lat, lon, and I want to find the area of the square in meters. I convert the CLLocationCoordinate2D points into MKMapPoints, and I find the area in X-Y space. However, the area I find is in the units of MKMapPoint, which don’t directly translate to meters. How can I translate this area in MKMapPoint-space back into meters?
- GoogleMapsUtils Framework wrapped in Cocoapods Build error on Xcode
- myLocationEnabled changing to isMyLocationEnabled on swift when using GoogleMaps
- Google Maps for iOS, swift - How to show entire polyline between markers?
- Linker errors in a Swift project with Google Maps for iOS added via CocoaPods
- Google Places API for iOS vs Google places Web service
- GoogleMaps on simulator in Xcode 9 uses over 100% of CPU when moving the map
2 Solutions Collect From Internet About “iphone — convert MKMapPoint distances to meters”
The MapKit function
MKMetersBetweenMapPoints makes this easier.
For example, if you wanted to get the area of the currently displayed region:
MKMapPoint mpTopLeft = mapView.visibleMapRect.origin; MKMapPoint mpTopRight = MKMapPointMake( mapView.visibleMapRect.origin.x + mapView.visibleMapRect.size.width, mapView.visibleMapRect.origin.y); MKMapPoint mpBottomRight = MKMapPointMake( mapView.visibleMapRect.origin.x + mapView.visibleMapRect.size.width, mapView.visibleMapRect.origin.y + mapView.visibleMapRect.size.height); CLLocationDistance hDist = MKMetersBetweenMapPoints(mpTopLeft, mpTopRight); CLLocationDistance vDist = MKMetersBetweenMapPoints(mpTopRight, mpBottomRight); double vmrArea = hDist * vDist;
The documentation states that the function takes “into account the curvature of the Earth.”
You can use the Haversine formula to calculate it, assuming that the earth is a perfect sphere.
To understand how lat/lon vs meters works in the context of the earth, you may find it interesting to read about Nautical miles.
You can find some more resources and some sample code by googling objective-c Haversine formula.
- ViewDidLoad / Unload messages to super?
- Background iPod music Volume mixed with sound effects
- Swift – Delegate Protocol structure
- Could not cast value of type 'NSTaggedPointerString' to 'NSNumber'
- How do I set bold and italic on UILabel of iPhone/iPad?
- Xcode ARC (automatic reference counting), “release is unavailable”
- compiling and signing xcode project on Windows
- fatal error: high- and low-surrogate code points are not valid Unicode scalar values
- Copying of NSMutableArray from one viewcontroller to another viewcontroller?
- Getting the last day of a month
- Launching XCode Simulator with jenkins user
- Detect when UITableViewCell goes out of scope
- Cannot change the height of Login Button in FBSDKLoginKit?
- Swift enum and NSCoding
- iOS – Calling App Delegate method from ViewController