Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I calculate the distance between two points in MkMapview?

In an iPhone App how can you calculate distance between two points in MKMapView as shown in the image below?

The first point would be the center point of the visible map in the mapview.

The 2nd point would be any of corner of the visible rectangle of the mapview (here, for example I have taken the top left point).

enter image description here

I want to calculate this distance in meters. How can I achieve that?

My goal is to calculate the ratios of the visible Map rectangle in MKMapview.

like image 234
ios Avatar asked Nov 03 '11 10:11

ios


1 Answers

You can get lat/lon of the center with:

convertPoint:toCoordinateFromView:

loc1 and loc2 are both CLLocation objs.

CLLocationDistance dist = [loc1 distanceFromLocation:loc2];

So these two tips should help you. if you need some code, let me know :-)

like image 180
danielreiser Avatar answered Nov 15 '22 13:11

danielreiser