【问题标题】:How to draw GMSPolyline slowly and smoothly in iOS?如何在 iOS 中缓慢流畅地绘制 GMSPolyline?
【发布时间】:2016-09-19 07:40:26
【问题描述】:

我可以在 GoogleMaps 上绘制 GMSPolyline,其中包含这样的位置数组

GMSMutablePath *path = [GMSMutablePath path];

    for (int i = 0; i <anotherArray.count; i++) {

        NSString *string1 = [anotherArray2 objectAtIndex:i];
        NSString *string2 = [anotherArray objectAtIndex:i];
        [path addCoordinate:CLLocationCoordinate2DMake(string1.doubleValue,string2.doubleValue)];
    }

        GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
        rectangle.strokeColor = [UIColor blueColor];
        rectangle.map = mapView_;
        rectangle.strokeWidth = 2.0f;

但是我从后端服务器获取的位置。

所以我必须每 10 秒刷新一次,获取新位置并将其添加到现有路径。这些都工作正常。

但是当我向现有路径添加新位置时,移动速度非常快。

因为我在路径的起点有一个 GMSMarker,它看起来像是从一个地方跳到另一个地方。

那么我怎样才能让 GMSMarker 像从一个地方慢慢移动到另一个地方一样制作动画呢?

【问题讨论】:

    标签: ios objective-c xcode google-maps animation


    【解决方案1】:

    检查此tutorial。它说明了如何使用GMSPolyline 类在地图上绘制路线。来自related SO thread

    将 else 块更改为更像这样:

    [CATransaction begin];
    [CATransaction setAnimationDuration:2.0];
    marker.position = coordindates;
    [CATransaction commit];
    

    我们允许您使用Core Animation 用于为 Google 地图制作动画。

    有关工作示例,请参阅 SDK 示例中的AnimatedCurrentLocationViewController.{c,m} 应用。

    同样基于SO post,避免使用 1px 笔画宽度的线条。相反,使用 4px 笔画宽度。您也可以查看GitHub sample

    【讨论】:

    • 感谢您的详细说明。让我检查一下
    猜你喜欢
    • 2015-09-15
    • 2015-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    • 2023-03-18
    • 2015-09-28
    相关资源
    最近更新 更多