DoubleMapViewController.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #if !defined(__has_feature) || !__has_feature(objc_arc)
  2. #error "This file requires ARC support."
  3. #endif
  4. #import "SDKDemos/Samples/DoubleMapViewController.h"
  5. #import <GoogleMaps/GoogleMaps.h>
  6. @interface DoubleMapViewController () <GMSMapViewDelegate>
  7. @end
  8. @implementation DoubleMapViewController {
  9. GMSMapView *_mapView;
  10. GMSMapView *_boundMapView;
  11. }
  12. + (GMSCameraPosition *)defaultCamera {
  13. return [GMSCameraPosition cameraWithLatitude:37.7847
  14. longitude:-122.41
  15. zoom:5];
  16. }
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Two map views, second one has its camera target controlled by the first.
  20. CGRect frame = self.view.bounds;
  21. frame.size.height = frame.size.height / 2;
  22. _mapView = [GMSMapView mapWithFrame:frame camera:[DoubleMapViewController defaultCamera]];
  23. _mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
  24. UIViewAutoresizingFlexibleHeight |
  25. UIViewAutoresizingFlexibleBottomMargin;
  26. _mapView.delegate = self;
  27. [self.view addSubview:_mapView];
  28. frame = self.view.bounds;
  29. frame.size.height = frame.size.height / 2;
  30. frame.origin.y = frame.size.height;
  31. _boundMapView =
  32. [GMSMapView mapWithFrame:frame camera:[DoubleMapViewController defaultCamera]];
  33. _boundMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
  34. UIViewAutoresizingFlexibleHeight |
  35. UIViewAutoresizingFlexibleTopMargin;
  36. _boundMapView.settings.scrollGestures = NO;
  37. [self.view addSubview:_boundMapView];
  38. }
  39. - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  40. duration:(NSTimeInterval)duration {
  41. CGRect frame = self.view.bounds;
  42. frame.size.height = frame.size.height / 2;
  43. _mapView.frame = frame;
  44. }
  45. - (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position {
  46. GMSCameraPosition *previousCamera = _boundMapView.camera;
  47. _boundMapView.camera = [GMSCameraPosition cameraWithTarget:position.target
  48. zoom:previousCamera.zoom
  49. bearing:previousCamera.bearing
  50. viewingAngle:previousCamera.viewingAngle];
  51. }
  52. @end