2013-10-22 3 views
1

IOS 개발을 처음 접했고 샘플 앱에 Google지도를 추가하려고합니다. 나는 https://developers.google.com/maps/documentation/ios/에서 튜토리얼을 사용하고있다. Google지도가 전체 화면을 사용한다는 것을 제외하고는 모든 것이 잘 작동합니다. 구글지도를 표시하는 코드는특정 장소에 Google지도 표시

#import <GoogleMaps/GoogleMaps.h> 
#import "DemoViewController.h" 

@implementation DemoViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868 
                  longitude:151.2086 
                   zoom:6]; 
    GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 

    GMSMarker *marker = [[GMSMarker alloc] init]; 
    marker.position = camera.target; 
    marker.snippet = @"Hello World"; 
    marker.animated = YES; 

    self.view = mapView; 
} 

@end 

다음은 구글지도 전체 화면을 복용하는 이유 이유 때문에 self.view =지도보기의이다;. 전체 화면을 차지하지 않도록 Google지도를 추가하려면 어떻게해야합니까?

다음과 같이 SubView를 사용해 보았지만 여전히 작동하지 않습니다. 코드는 다음과 같습니다

ViewController.h

@interface ViewController : UIViewController 
@property UIView *myView; 
@end 

ViewController.m으로 viewDidLoad 방법에 self.view = mapView_;을 대체 할

#import "ViewController.h" 
#import <GoogleMaps/GoogleMaps.h> 

@interface ViewController() 

@end 

@implementation ViewController{ 
    GMSMapView *mapView_; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    CGRect viewRect = CGRectMake(0, 0, 100, 100); 
    _myView = [[UIView alloc] initWithFrame:viewRect]; 
    [self.view addSubview:_myView]; 



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

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 
@end 
+0

새로운 서브뷰로 시도하고 그 서브뷰에서'mapView'를 추가해 주시겠습니까? –

+0

서브 뷰를 시도하겠습니다. – Noor

+0

완료되면 알려주십시오. –

답변

1

시도 :

[self.view addSubview:mapView_]; 
,536,

그러면 현재보기에 mapview가 하위보기로 추가됩니다. 당신지도보기의 프레임을 설정

편집

보십시오. 전에 [self.view addSubview : mapView_]; 시도 :

mapView_.frame = CGRectMake(10,10,100,100)]; 

mapview에 대해 원하는 프레임에 대해 1010100100을 변경하십시오.

+0

이 작동하지 않습니다. ( – Noor

+0

뷰를 초기화하기 위해 drawRect 메서드를 호출해야한다고 생각합니까? – Noor

+0

@Noor never. drawRect를 호출하지 마십시오. 시스템에서 자동으로 호출합니다. 메시지를 보냅니다. 강제적으로 재 묘화를 실시하는 setNeedsDisplay. –

관련 문제