我试图在谷歌地图上显示多个标记和它们之间的一条线

时间:2017-03-04 08:48:26

标签: ios objective-c google-maps-sdk-ios

for (int i=0; i<self.busRoutesArr.count-1; i++)
{
    NSString *lat = [self.latArr objectAtIndex:i];
    NSString *lon = [self.longArr objectAtIndex:i] ;
    double lt=[lat doubleValue];
    double ln=[lon doubleValue];
    NSLog(@"%f, %f",lt,ln);

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lt
                                                            longitude:ln
                                                                 zoom:60];


    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectMake(10, 100, 250, 250) camera:camera];

    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = camera.target;
    marker.snippet = @"Hello World";
    marker.map = mapView;
    mapView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:mapView];
}
  

仅显示1个标记。我想显示所有标记和连接它们的线

1 个答案:

答案 0 :(得分:0)

以下代码用于显示地图中的所有标记。

for(int i=0;i<[array count];i++)    {       
      GMSMarker *marker = [[GMSMarker alloc] init];
      marker.animated=YES;
      marker.position = CLLocationCoordinate2DMake(latitude,longitude);
      marker.title = @"name";
      marker.snippet = @"snippet";
      marker.map = mapView;    
}