2014-10-06 4 views
1

iOS 8.0의 Google지도에서 여러 마커를 얻으려고 애 쓰고 있습니다. 나의 현재 코드는 다음과 같습니다 내 배열을 통해 반복,하지만 내 배열 수가 2 또는 3 선택한 항목 사용자에 따라 달라집니다처럼 동안 만 1 개 마커를 참조다중 마커 Google지도 iOS SDK

ResourceGroep *rsg = [ResourceGroep alloc]init; 
GMSCameraPosition *camera = nil; 

for (int i = 0; i < [rsg.chosenResourceArray count]; i++) 
{ 
    camera = [GMSCameraPosition cameraWithLatitude:[loc.Latitude doubleValue] 
           longitude:[loc.Long doubleValue] 
           zoom:15]; 

    mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; 
    mapView_.myLocationEnabled = NO; 

    CLLocationCoordinate2D position = { [rsg.Latitude doubleValue], [rsg.Long doubleValue] }; 
    GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
     marker.title = [NSString stringWithFormat:@"Marker %i", i]; 
     marker.appearAnimation = YES; 
     marker.flat = YES; 
     marker.snippet = @""; 
     marker.map = mapView_; 
} 

[self.view addSubview:mapView_]; 

. 내가 뭘 놓치고 있니?

+0

move camera = ..., mapView_ = ... 루프에서 루프 아웃. 매번 새로운 mapView를 만들 때 – kabarga

답변

4

확인이 :

ResourceGroep *rsg = [ResourceGroep alloc]init; 
    GMSCameraPosition *camera = nil; 

    camera = [GMSCameraPosition cameraWithLatitude:[loc.Latitude doubleValue] 
          longitude:[loc.Long doubleValue] 
           zoom:15]; 

    mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; 
    mapView_.myLocationEnabled = NO; 

    for(int i = 0; i < [rsg.chosenResourceArray count]; i++) 
    { 




     CLLocationCoordinate2D position = { [rsg.Latitude doubleValue], [rsg.Long doubleValue] }; 
     GMSMarker *marker = [GMSMarker markerWithPosition:position]; 
     marker.title = [NSString stringWithFormat:@"Marker %i", i]; 
     marker.appearAnimation = YES; 
     marker.flat = YES; 
     marker.snippet = @""; 
     marker.map = mapView_; 
    } 

[self.view addSubview:mapView_]; 

난 그냥 코드의 일부 위치를 변경했습니다.

+0

어떻게? 내 위치에 대한 모든 값을 포함하고 있기 때문에 루프 내에 [loc.Latitude doubleValue]와 [loc.Long doubleValue]가 있어야하기 때문에? –

0

루프 외부에 이러한 라인을 넣으면 도움이됩니다.

camera = [GMSCameraPosition cameraWithLatitude:[loc.Latitude doubleValue] 
          longitude:[loc.Long doubleValue] 
           zoom:15]; 

mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; 
mapView_.myLocationEnabled = NO; 

마커를 추가 할 때마다지도가 초기화됩니다. 초기화는 지금까지 추가 된 모든 마커를 지 웁니다.

+0

어떻게? 내 위치에 대한 모든 값을 포함하고 있기 때문에 루프 내에 [loc.Latitude doubleValue]와 [loc.Long doubleValue]가 있어야하기 때문에? –

0

나는 그것이 또한 유익 할 것이라는 점을 희망하는 제일 방법을 얻었다.

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:_sourceloc.latitude longitude:_sourceloc.longitude zoom:6]; 
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 


GMSMarker *marker = [GMSMarker markerWithPosition:_sourceloc]; 
[email protected]"Source"; 
marker.snippet =_sourceAdd; 
marker.appearAnimation = kGMSMarkerAnimationPop; 
marker.map = mapView; 


GMSMarker *marker2 = [GMSMarker markerWithPosition:_destinationloc]; 
[email protected]"Destination"; 
marker2.snippet =_destinationAdd; 
marker2.appearAnimation = kGMSMarkerAnimationPop; 
marker2.map = mapView; 

self.view = mapView;