iPhone App:计算Google地图中的路径距离

时间:2012-05-01 03:18:47

标签: iphone objective-c google-maps mapkit

我正在开发一款iPhone应用程序。在我的应用程序中,我已经包含了Google地图。我在地图中显示突出显示的路径。

现在我的问题是如何根据路径计算两点之间的距离,因为Apple的原生地图App正在显示距离的路线。

先谢谢。

2 个答案:

答案 0 :(得分:0)

    CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];
    CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.latitude];

    CLLocationDistance distance = ([loc2 distanceFromLocation:loc1]) * 0.000621371192;

答案 1 :(得分:0)

这可能会对你有帮助。

在模拟器中运行时,Core Location会为此属性分配一组固定的坐标值。您必须在基于iOS的设备上运行应用程序才能获得真实的位置值。

CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.latitude];