Google maps 在Objective C中的Google地图上显示多个标记

Google maps 在Objective C中的Google地图上显示多个标记,google-maps,google-maps-mobile,google-maps-sdk-ios,Google Maps,Google Maps Mobile,Google Maps Sdk Ios,如何在iOS中在Google地图上显示多个标记? 我使用了下面的方法,但不起作用 for (int i = 0; i < [array count]; i++) { pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:0] componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:

如何在iOS中在Google地图上显示多个标记? 我使用了下面的方法,但不起作用

for (int i = 0; i < [array count]; i++)
{
     pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);
     [_map animateToLocation:pointsToUse[i]];
      GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
      options.position = pointsToUse[i];
    [_map animateToLocation:pointsToUse[i]];
    [_map addMarkerWithOptions:options];
}
for(int i=0;i<[数组计数];i++)
{
点使用[i]=CLLocationCoordinate2DMake([[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:0]浮点值分离],[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:1]浮点值分离];
[_mapanimateTocation:pointsToUse[i]];
GMSMarkerOptions*options=[[GMSMarkerOptions alloc]init];
options.position=pointsToUse[i];
[_mapanimateTocation:pointsToUse[i]];
[_mapaddmarker with options:options];
}

您正在使用
[array objectAtIndex:0]
(两处),而我认为您可能应该使用
[array objectAtIndex:I]


另外,您可能不需要调用
animateToLocation

您正在使用
[array objectAtIndex:0]
(在两个位置),而我认为您可能应该使用
[array objectAtIndex:I]


另外,您可能不需要调用
animateToLocation

我尝试了您的代码。这似乎很有效。将索引0处的对象的值传递给pointsToUse后,只需删除该对象即可

NSMutableArray *array = [NSMutableArray arrayWithObjects:@"12.981902,80.266333",@"12.982902,80.266363", nil];

CLLocationCoordinate2D pointsToUse[5];

for (int i = 0; i < [array Size]; i++)
{
    pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);

      [array removeObjectAtIndex:0];

    GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
    options.position = pointsToUse[i];
    [mapView_ animateToLocation:pointsToUse[i]];
    [mapView_ addMarkerWithOptions:options];
}
NSMUTABLEARRY*array=[NSMUTABLEARRY arrayWithObjects:@“12.981902,80.266333”,“12.982902,80.266363”,无];
CLLocationCoordination2D点使用[5];
对于(int i=0;i<[数组大小];i++)
{
点使用[i]=CLLocationCoordinate2DMake([[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:0]浮点值分离],[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:1]浮点值分离];
[array removeObjectAtIndex:0];
GMSMarkerOptions*options=[[GMSMarkerOptions alloc]init];
options.position=pointsToUse[i];
[mapView_uuAnimateToLocation:pointsToUse[i]];
[mapView_uu;addMarkerWithOptions:选项];
}

我尝试了你的代码。这似乎很有效。将索引0处的对象的值传递给pointsToUse后,只需删除该对象即可

NSMutableArray *array = [NSMutableArray arrayWithObjects:@"12.981902,80.266333",@"12.982902,80.266363", nil];

CLLocationCoordinate2D pointsToUse[5];

for (int i = 0; i < [array Size]; i++)
{
    pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);

      [array removeObjectAtIndex:0];

    GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
    options.position = pointsToUse[i];
    [mapView_ animateToLocation:pointsToUse[i]];
    [mapView_ addMarkerWithOptions:options];
}
NSMUTABLEARRY*array=[NSMUTABLEARRY arrayWithObjects:@“12.981902,80.266333”,“12.982902,80.266363”,无];
CLLocationCoordination2D点使用[5];
对于(int i=0;i<[数组大小];i++)
{
点使用[i]=CLLocationCoordinate2DMake([[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:0]浮点值分离],[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:1]浮点值分离];
[array removeObjectAtIndex:0];
GMSMarkerOptions*options=[[GMSMarkerOptions alloc]init];
options.position=pointsToUse[i];
[mapView_uuAnimateToLocation:pointsToUse[i]];
[mapView_uu;addMarkerWithOptions:选项];
}

是的,你们都是对的。根据你的建议,我修改了代码,它工作了。 但问题是,我设置了缩放,缩放是固定的。如果两个位置都很远,我无法在一个屏幕上同时看到这两个位置(我需要捏一下才能同时看到这两个位置)。如何同时看到两个位置? 我的代码如下所示

-(void) displayMapwithPositionfortheArray:(NSMutableArray*) array
{
    CLLocationCoordinate2D firstPoint = CLLocationCoordinate2DMake([[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);
    GMSCameraPosition *currloc = [GMSCameraPosition cameraWithLatitude:firstPoint.latitude
                                                         longitude:firstPoint.longitude
                                                              zoom:8
                                                           bearing:0
                                                      viewingAngle:45];


    _map = [GMSMapView mapWithFrame:CGRectZero camera:currloc];
    _map.myLocationEnabled = YES;
    _map.frame = CGRectMake(0, heightOffset, self.view.frame.size.width, self.view.frame.size.height - heightOffset);
    [self.view addSubview:_map];

    CLLocationCoordinate2D pointsToUse[[array count]];
    for (int i = 0; i < [array count]; i++)
    {
          pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:i]  componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:i]  componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);

          GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
          options.position = pointsToUse[i];
          [_map addMarkerWithOptions:options];
    }
}
-(void)displayMapwithPositionfortheArray:(NSMutableArray*)数组
{
CLLocationCoordinate2D firstPoint=CLLocationCoordinate2DMake([[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:0]浮点值分离],[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:1]浮点值分离];
GMSCameraPosition*currloc=[GMSCameraPosition摄影机使用纬度:第一点。纬度
经度:第一点。经度
缩放:8
方位:0
视角:45];
_map=[GMSMapView mapWithFrame:CGRectZero摄像机:currloc];
_map.myLocationEnabled=是;
_map.frame=CGRectMake(0,heightOffset,self.view.frame.size.width,self.view.frame.size.height-heightOffset);
[self.view addSubview:_map];
CLLocationCoordinate2D点使用[[数组计数]];
对于(int i=0;i<[数组计数];i++)
{
点使用[i]=CLLocationCoordinate2DMake([[[[array objectAtIndex:i]Components由字符串@',“]objectAtIndex:0]浮点值分离],[[[array objectAtIndex:i]Components由字符串@',“]objectAtIndex:1]浮点值分离];
GMSMarkerOptions*options=[[GMSMarkerOptions alloc]init];
options.position=pointsToUse[i];
[_mapaddmarker with options:options];
}
}

是的,你们都是对的。根据你的建议,我修改了代码,它工作了。 但问题是,我设置了缩放,缩放是固定的。如果两个位置都很远,我无法在一个屏幕上同时看到这两个位置(我需要捏一下才能同时看到这两个位置)。如何同时看到两个位置? 我的代码如下所示

-(void) displayMapwithPositionfortheArray:(NSMutableArray*) array
{
    CLLocationCoordinate2D firstPoint = CLLocationCoordinate2DMake([[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:0]  componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);
    GMSCameraPosition *currloc = [GMSCameraPosition cameraWithLatitude:firstPoint.latitude
                                                         longitude:firstPoint.longitude
                                                              zoom:8
                                                           bearing:0
                                                      viewingAngle:45];


    _map = [GMSMapView mapWithFrame:CGRectZero camera:currloc];
    _map.myLocationEnabled = YES;
    _map.frame = CGRectMake(0, heightOffset, self.view.frame.size.width, self.view.frame.size.height - heightOffset);
    [self.view addSubview:_map];

    CLLocationCoordinate2D pointsToUse[[array count]];
    for (int i = 0; i < [array count]; i++)
    {
          pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:i]  componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:i]  componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);

          GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
          options.position = pointsToUse[i];
          [_map addMarkerWithOptions:options];
    }
}
-(void)displayMapwithPositionfortheArray:(NSMutableArray*)数组
{
CLLocationCoordinate2D firstPoint=CLLocationCoordinate2DMake([[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:0]浮点值分离],[[[array objectAtIndex:0]组件按字符串@',“]objectAtIndex:1]浮点值分离];
GMSCameraPosition*currloc=[GMSCameraPosition摄影机使用纬度:第一点。纬度
经度:第一点。经度
缩放:8
方位:0
视角:45];
_map=[GMSMapView mapWithFrame:CGRectZero摄像机:currloc];
_map.myLocationEnabled=是;
_map.frame=CGRectMake(0,heightOffset,self.view.frame.size.width,self.view.frame.size.height-heightOffset);
[self.view addSubview:_map];
CLLocationCoordinate2D点使用[[数组计数]];
对于(int i=0;i<[数组计数];i++)
{
指向