【问题标题】:draw route with multiple markers on Google Map iOS在 Google Map iOS 上使用多个标记绘制路线
【发布时间】:2015-12-17 17:48:03
【问题描述】:

我是 iPhone 开发的新手,在我的应用程序中,我想在两点之间绘制路线并在我的路线上显示多个标记。现在我完成了两点之间的路线,但我不知道如何在我的路线上绘制多个标记。所以请帮我做这件事。

提前致谢!!!

_markerStart = [GMSMarker new];
_markerStart.title = [[[routeDict objectForKey:@"legs"] objectAtIndex:0]objectForKey:@"start_address"];
_markerStart.icon = newImage; //[UIImage imageNamed:@"startMarker.png"];
_markerStart.map = gmsMapView;
_markerStart.position = startPoint;

_markerFinish = [GMSMarker new];
_markerFinish.title = [[[routeDict objectForKey:@"legs"] objectAtIndex:0]objectForKey:@"end_address"];
_markerFinish.icon = newImage; //[UIImage imageNamed:@"finishMarker.png"];
_markerFinish.map = gmsMapView;
_markerFinish.position = endPoint;

这里我添加了开始和结束标记。

【问题讨论】:

  • 您是否只完成了端点的绘图标记?还是绘制完整的路线?
  • 是的..现在我想要更多的路线

标签: ios iphone google-maps-markers


【解决方案1】:

当您在两点之间绘制路线时,您将获得路线坐标。您可以从中获取一些坐标并在 Google 地图上绘制它们。

对于绘图路线,您可能使用过GMSPolyline。对于折线,您必须使用GMSPath。从路径中,您可以使用方法获取坐标

-(CLLocationCoordinate2D)coordinateAtIndex:(NSUInteger)index

GMSPath Doc

您可以使用这些坐标在路线上绘制标记。 GMSMarkers Doc

检查此代码(此处 gmsPath 为 GMSPath编辑

//GMSPath *gmsPath;
//NSString *title;
for (int i = 0; i < [gmsPath count]; i++) {
    CLLocationCoordinate2D location = [gmsPath coordinateAtIndex: i];
    GMSMarker *marker = [GMSMarker markerWithPosition:location];
    marker.title = title;
    marker.icon = [UIImage imageNamed:@"marker_img.png"];
    marker.map = self.mapView;
}

这将为每个坐标绘制标记。

【讨论】:

  • for 循环条件给出错误:二进制表达式的操作数无效
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-20
  • 1970-01-01
  • 2017-03-01
  • 1970-01-01
  • 2019-05-17
  • 2015-09-06
  • 2014-08-09
相关资源
最近更新 更多