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
디버거를 통해 이것을 사용 해보았습니까? 예상되는 경로를 따르고 있습니까? 당신은 예상되는 물체를 얻었습니까? – rmaddy
그래, 내가 디버깅, 나는 예상대로 개체를 받고있다. – Karthick
Mark의 프레임 설정에 대한 제안을 올바르게 시도 했습니까? – rmaddy