2013-09-29 2 views
1

Google지도를 공장 디자인 패턴으로 구현했습니다. 그러나지도보기를로드 할 때지도가 표시되지 않습니다. 팩토리 패턴을 사용하지 않고 동일한 코드를 구현하면 성공적으로로드 될 수 있습니다. 이 문제를 해결하도록 도와주세요. 아래는 코드입니다. GoogleMapsViewControlleriOS 공장 디자인 패턴

의 MapBuilderFactory

 //Caller 
    #import "ViewController.h" 
    #import "Constants.h" 
    #import "MapBuilderFactory.h" 
    #import "MapBuilderDelegate.h" 

    - (void)viewDidLoad 
    { 
      [super viewDidLoad]; 
      id<MapBuilderDelegate> mapBuilder=[MapBuilderFactory mapWithName:GoogleMaps];      
      [mapBuilder initMapWithApiKey:kGoogleMapsApiKey]; 
      UIView *mapView= [mapBuilder mapView]; 
      [self.view addSubview:mapView]; 

    } 

구현

 #import "MapBuilderFactory.h" 
     #import "GoogleMapsViewController.h" 
     @implementation MapBuilderFactory 

     +(id)mapWithName:(mapType)mapType 
     { 
      id returnValue; 
      switch (mapType) { 

      case AppleMaps: 
       returnValue=nil; 
       break; 
      case GoogleMaps: 
       returnValue=[GoogleMapsViewController new]; 
       break; 
      default: 
       break; 
     } 
     return returnValue; 
    } 
    @end 

구현

@interface GoogleMapsViewController() 

    @property(nonatomic,retain)GMSMapView *mapView; 

    @end 

    @implementation GoogleMapsViewController 

    @synthesize mapView=mapView_; 

    -(void)initMapWithApiKey:(NSString*)apiKey 
    { 
     [GMSServices provideAPIKey:apiKey]; 
    } 

    -(UIView*)mapView 
    { 
     // Create a GMSCameraPosition that tells the map to display the 
     // coordinate -33.86,151.20 at zoom level 6. 
     GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 
                 longitude:151.20 
                  zoom:6]; 
     mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 
     mapView_.myLocationEnabled = YES; 
     self.view = mapView_; 

     // Creates a marker in the center of the map. 
     GMSMarker *marker = [[GMSMarker alloc] init]; 
     marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); 
     marker.title = @"Sydney"; 
     marker.snippet = @"Australia"; 
     marker.map = mapView_; 
     return mapView_; 
    } 

MapBuilderDelegate

@protocol MapBuilderDelegate <NSObject> 

    -(void)initMapWithApiKey:(NSString*)apiKey; 

    -(UIView*)mapView; 

    @end 
+0

디버거를 통해 이것을 사용 해보았습니까? 예상되는 경로를 따르고 있습니까? 당신은 예상되는 물체를 얻었습니까? – rmaddy

+0

그래, 내가 디버깅, 나는 예상대로 개체를 받고있다. – Karthick

+0

Mark의 프레임 설정에 대한 제안을 올바르게 시도 했습니까? – rmaddy

답변

0

뷰의 문제 또는지도이다 configur ation? 나는 프레임이 지정된 곳을 보지 못했다. 아래에서 viewDidLoad에 setframe을 추가했습니다.

- (void)viewDidLoad 
{ 
     [super viewDidLoad]; 
     id<MapBuilderDelegate> mapBuilder=[MapBuilderFactory mapWithName:GoogleMaps];      
     [mapBuilder initMapWithApiKey:kGoogleMapsApiKey]; 
     UIView *mapView= [mapBuilder mapView]; 
     [mapView setFrame:CGRectMake(0.0, 0.0, 320.0, 500.0)]; 
     [self.view addSubview:mapView]; 

}