2013-02-25 3 views
0

iOS의 Google지도에 여러 마커를 표시하려면 어떻게해야합니까? 다음 접근 방식을 사용했지만 작동하지 않았습니다. 난 당신이 아마 [array objectAtIndex:i]를 사용한다고 생각하면Objective C의 Google Map에 여러 마커 표시

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]; 
} 

답변

0

당신은 [array objectAtIndex:0] (두에 위치)를 사용하는?

또한 animateToLocation으로 전화하지 않아도됩니까?

0

나는 당신의 코드를 시도했다. 이것은 잘 작동하는 것 같습니다. 값을 pointsToUse에 전달한 후 인덱스 0에서 객체를 삭제하면됩니다.

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]; 
} 
0

예 둘 다 맞습니다. 귀하의 제안에 따라 코드를 변경하고 작동합니다. 하지만 문제는 줌을 설정하고 줌이 고정되어 있다는 것입니다. 두 위치가 멀리 있으면 하나의 화면에서 두 위치를 볼 수 없습니다 (두 가지를 모두보기 위해 집어 넣어야 함). 같은 위치에 두 위치를 모두 표시하려면 어떻게해야합니까? 내 코드는 아래와 같습니다.

-(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]; 
    } 
} 
+0

안녕 @Bryanyan, 나는 단지이 게시물을 보았다. 다음 코드를 사용하여 경계 영역 (즉, 모든 마커)을 포함하도록 카메라를 설정할 수 있습니다. http://stackoverflow.com/questions/15040409/how-to-setregion-with-google-maps-sdk-for- 이오스 –

1

이 시도 :

-(void)plotMutliplePinsonMap 
{ 
    mapView_ = [[GMSMapView alloc]initWithFrame:CGRectMake(0, 96, 320, 450)]; 
    for(int i=0;i<[arrTobeShown count];i++) 
    { 
     double_lat = [[[arrTobeShown objectAtIndex:i]valueForKey:@"latitude"] doubleValue]; 
     double_long = [[[arrTobeShown objectAtIndex:i]valueForKey:@"longitude"] doubleValue]; 
     GMSMarker *mkr = [[GMSMarker alloc] init]; 
     if (double_lat !=0 && double_long!=0) 
     {   
      [mkr setPosition:CLLocationCoordinate2DMake(double_lat, double_long)]; 
      [mkr setTitle:[[arrTobeShown objectAtIndex:i] valueForKey:@"name"]]; 
      [mkr setSnippet:[[arrTobeShown objectAtIndex:i] valueForKey:@"address"]]; 
      [mkr setMap:mapView_]; 

      GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:double_lat longitude:double_long zoom:5]; 
     mapView_.camera=camera; 
     } 
    } 
    [self.view addSubview:mapView_]; 
    [mapView_ setHidden:YES]; 
    [self.view layoutIfNeeded]; 
}