MKCoordinateRegion Distance between center and borders

(Revised question based on comment :)

OK. I will try to ask in another way ... How to get the boundary coordinates of this circle overlay:

enter image description here


(Original question :)

I am having a strange problem with my iPhone app. I have an MKCoordinateRegion that has a central coordinate latitude: 51.509980 and longitude: -0.133700. I used the MKCoordinateRegionMakeWithDistance method and set the distance to 16,093.44 meters (10 miles).

I want to get the boundary point of this region, so I have this code:

MKCoordinateRegion region2 = self.myMapView.region; float minLat = region2.center.latitude - (region2.span.latitudeDelta / 2.0); float maxLat = region2.center.latitude + (region2.span.latitudeDelta / 2.0); float minLong = region2.center.longitude - (region2.span.longitudeDelta / 2.0); float maxLong = region2.center.longitude + (region2.span.longitudeDelta / 2.0); 

I found this site for testing http://boulter.com/gps/distance/ , which calculates the distance between two coordinates. When I enter the FROM coordinate: 51.509980 and the longitude: -0.133700 (London) and the KO coordinates:

 2011-11-26 01:15:42.830 NearMeTest[3911:11603] MinLAT 51.334381 and MaxLAT 51.684814 2011-11-26 01:15:42.830 NearMeTest[3911:11603] MinLONG -0.352936 and MaxLONG 0.086517 

I understand that the distance between these two coordinates is 15.40 miles instead of the expected 10 miles.

Screenshot:

enter image description here

Why such difference? When I tried to do the same, but from different coordinates of the center (Tokyo, New York), the result was correct 10 miles.

thanks for the answer

+4
source share
2 answers

(Revised answer based on comment :)

If you want the bounding box coordinates for this circle overlay, use the overlay boundingMapRect property:

 //"theCircle" is the MKCircle overlay object CLLocationCoordinate2D topLeftCoord = MKCoordinateForMapPoint(theCircle.boundingMapRect.origin); MKMapPoint bottomRightMapPoint = MKMapPointMake ( MKMapRectGetMaxX(theCircle.boundingMapRect), MKMapRectGetMaxY(theCircle.boundingMapRect)); CLLocationCoordinate2D bottomRightCoord = MKCoordinateForMapPoint(bottomRightMapPoint); 


(Original answer :)

First, when you call setRegion on a map, the map view almost always changes the requested region to match the map view. This setting is based on the shape of the map view and whether it can correctly display the requested range at one of the fixed zoom levels.

For example, if your map view is not square, and you request an interval of 10 miles in both directions, at least one of the spans will definitely be adjusted. Even if you ask for the range that you set based on the aspect ratio of the view, it can still be adjusted if the tile with this zoom level is not displayed on the map (or, possibly, if you did not take the Earth of curvature).

Further, latitudeDelta and longitudeDelta determine the entire height and width of the area (rather than the distance from the central coordinate).

Thus, your test in the screenshot cannot be compared with span deltas. In the screenshot, you calculate the distance from the central coordinate to the minimum latitude and longitude (lower left corner), but the delta deltas go all the way from right to left and from bottom to top. (Because of this, you might think that the distance from the center to the corner should be less than the delta - no more. It is shorter, but the delta also increased to more than 10 due to the reasons described above).

Finally, to get the angular coordinates (bottom left and top right), this is probably a more accurate way to do this:

 CLLocationCoordinate2D bottomLeftCoord = [myMapView convertPoint:CGPointMake(0, myMapView.frame.size.height) toCoordinateFromView:myMapView]; CLLocationCoordinate2D topRightCoord = [myMapView convertPoint:CGPointMake(myMapView.frame.size.width, 0) toCoordinateFromView:myMapView]; 
+2
source

In the screenshot of the web form, you get a different distance, because the line you are measuring (in the center of MinLAT / MinLONG) is diagonal and goes beyond the radius of the circle.

If you follow @AnnaKarenina's answer, you can get the distance in meters by converting each CLLocationCoordinate2D to CLLocation .

Here you will get the radius in miles:

 CLLocation * centerLeftLocation = [[CLLocation alloc] initWithLatitude:centerCoord.latitude longitude:topLeftCoord.longitude]; CLLocation * centerLocation = [[CLLocation alloc] initWithLatitude:centerCoord.latitude longitude:centerCoord.longitude]; CLLocationDistance distanceInMeters = [centerLeftLocation distanceFromLocation:centerLocation]; float distanceInMiles = distanceInMeters / 1609.344f; [centerLeftLocation release]; [centerLocation release]; 
0
source

Source: https://habr.com/ru/post/1383146/


All Articles