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
새로운 서브뷰로 시도하고 그 서브뷰에서'mapView'를 추가해 주시겠습니까? –
서브 뷰를 시도하겠습니다. – Noor
완료되면 알려주십시오. –