Ios 谷歌地图SDK-路径不准确

Ios 谷歌地图SDK-路径不准确,ios,google-maps,Ios,Google Maps,我试图显示两个位置之间的路径,但它不准确 if(center.latitude != 0 && center.longitude != 0) { NSString *urlString = [NSString stringWithFormat: @"%@?origin=%f,%f&destination=%f,%f&sensor=true&

我试图显示两个位置之间的路径,但它不准确

if(center.latitude != 0 && center.longitude != 0)
            {
            NSString *urlString = [NSString stringWithFormat:
                                   @"%@?origin=%f,%f&destination=%f,%f&sensor=true&key=%@",
                                   @"https://maps.googleapis.com/maps/api/directions/json",
                                   center.latitude,
                                   center.longitude,
                                   center1.latitude,
                                   center1.longitude,
                                   KGoogleMapServerKey];

            NSError *error;
                NSDictionary *json =[NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString] options:NSDataReadingUncached error:&error] options:NSJSONReadingMutableContainers error:&error];
            if(json[@"routes"] != nil && [json[@"routes"] count] > 0)
            {
                GMSPath *path =[GMSPath pathFromEncodedPath:json[@"routes"][0][@"overview_polyline"][@"points"]];
                GMSPolyline *singleLine = [GMSPolyline polylineWithPath:path];
                singleLine.strokeWidth = 7;
                singleLine.strokeColor = [UIColor colorWithRed:56.0/255.0 green:163.0/255.0 blue:249.0/255.0 alpha:1.0];
                singleLine.map = mapViewGoogle;
            }  
这是我得到的路径:

如您所见,蓝线(路径)不在目的地。

如何解决这一问题?

问题的关键在于,该目的地没有路线,正如您在这里看到的:

我想你最好的选择是使用GMAP已经使用的方法,我的意思是使用点/虚线多段线,从最后一点你可以得到到实际点的方向

您可以在这里找到实现您的多段线类型的两个示例:


您的路线太长了。在谷歌方向API的每个响应中,点数是有限的。在您的示例中,您收到了N个点,用它们绘制了路线,并将地图视图缩放到仅放置了四个点的区域。
要显示始终准确的路线,您应在每次地图缩放后重新计算路线(包括中点以保持路线不变)。
例如,屏幕上的完整路线有50个点。您正在缩放地图,因此仅显示4个点(屏幕截图)。现在以#1为起点,以#5为终点,以#2#3#4为中点,发送新请求以查找这些点的路线。您将获得新的50点积分,使用这些积分,您可以更准确地绘制路线的这一部分。


我认为谷歌不知道如何到达目的地,因为那里没有路线,或者在私人区域有类似的地方。如果这是真的,那么为什么谷歌地图会正确显示路径?这似乎是合理的。谢谢