如何计算MkMapview中两点之间的距离? [英] How can I calculate the distance between two points in MkMapview?

查看:417
本文介绍了如何计算MkMapview中两点之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone应用程序中,如何计算 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.

第二点是可见矩形的任何一个角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).

我想计算这个距离,以米为单位。

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

我的目标是计算 MKMapview 中可见的Map矩形的比率。 / p>

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

推荐答案

您可以通过以下方式获取中心的纬度:

You can get lat/lon of the center with:

convertPoint:toCoordinateFromView:



loc1和loc2都是CLLocation对象。

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 :-)

这篇关于如何计算MkMapview中两点之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆