0

在我的应用程序中,我正在创建从源到目的地的路线,并使用谷歌方向 api,在文本框中也显示行车路线。我正在解析 json 格式的方向响应并显示 html 指令。问题是假设我在 A 位置并且在 B 位置有一个转弯,那么当我到达 B 而不是在那之前,我在 B 位置获得相关的 html 指令。

我用来显示方向的逻辑是:

1. Parse the json response and store the html instructions and their relevant coordinates   in a array
2. Checking the current updated location
3. Checking whether the current updated location value is present in the array, if present then displaying the html instruction corresponding to the coordinate
4

1 回答 1

0

我通过计算当前更新位置和结束位置之间的距离解决了这个问题,如果这两个坐标之间的距离小于 100 米,那么我将显示该坐标的 html 指令。

您可以使用以下代码计算两个坐标之间的距离:

CLLocation *currentLoc = [[CLLocation alloc] initWithLatitude:startLat longitude:startLong]
CLLocation *endLoc = [[CLLocation alloc] initWithLatitude:endLat longitude:endLong];
CLLocationDistance meters = [endLoc distanceFromLocation:currentLoc];
于 2012-08-14T04:41:34.523 回答