ios - 在 ios 中使用 googlemap 显示两个位置之间的路线?

标签 ios objective-c google-maps

我必须使用谷歌地图显示两个位置之间的路线,但我得到的只是两个位置之间的直线,我使用下面的代码

- (void)viewDidLoad {
    [super viewDidLoad];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;



    GMSMutablePath *path = [GMSMutablePath path];
    [path addCoordinate:CLLocationCoordinate2DMake(@(-33.860).doubleValue,@(151.208).doubleValue)];
    [path addCoordinate:CLLocationCoordinate2DMake(@(-32.860).doubleValue,@(150.208).doubleValue)];

    GMSPolyline *rectangle = [GMSPolyline polylineWithPath:path];
    rectangle.strokeWidth = 2.f;
    rectangle.map = mapView_;

    self.view = mapView_;

}

请告诉我如何做到这一点,我以前见过各种此类问题,但没有得到。 请帮我... 任何帮助将不胜感激...

最佳答案

这样不行。您只向 GMSMutablePath 添加了两个坐标,因此生成的 GMSPolyline 是一条直线。

如果您想获取两点之间的路线,您需要使用路线 API,例如 Google Maps Directions API使用 HTTP 请求计算位置之间的方向。

关于ios - 在 ios 中使用 googlemap 显示两个位置之间的路线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38432457/

相关文章:

ios - 本地化应用程序时,UITextField 占位符颜色不同

iphone - 为推送通知配置 ‘App store distribution provision profile’ 的步骤

iphone - UICollectionView:一行或一列

javascript - 在 Openlayer 中添加谷歌地图图层。有什么要求?

ios - 即使我设置了 `numberOfLines = 0`,UILabel 也不换行

ios - swift/alamofire/api token /缺少必需参数 : grant_type

iphone - 页面加载后可以立即播放声音吗?

objective-c - self.frame 返回不同的值

regex - 我如何使用express在Nodejs中创建像API这样的谷歌地方

google-maps - 自定义 html 为谷歌地图制作标记