ios – 谷歌地图SDK – 路径不准确

我试图显示两个位置之间的路径,但它不准确.
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;
            }

这是我得到的道路:

如您所见,蓝线(路径)不会到达目的地.
如何解决这个问题?

解决方法

你的路线太长了.在Google Directions API的每个回复中,点数都是有限的.在您的示例中,您收到N个点,使用它们绘制路线并将mapView缩放到区域,其中只放置了四个点.
要显示始终准确的路线,您应该在每次地图缩放后重新计算路线(包括中点以保持路线相同).
例如,屏幕上的完整路线有50个点.您正在缩放地图,因此仅显示4个点(您的屏幕截图).现在以#1为开始,#5为完成,#2#3#4为中点,并发送新请求以查找这些点的路由.您将获得新的50分,通过它们,您可以更准确地绘制这部分路线.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...