DoubleMapViewController.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2016 Google Inc. All rights reserved.
  3. *
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  6. * file except in compliance with the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed under
  11. * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
  12. * ANY KIND, either express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #import "GoogleMapsDemos/Samples/DoubleMapViewController.h"
  16. #import <GoogleMaps/GoogleMaps.h>
  17. @interface DoubleMapViewController () <GMSMapViewDelegate>
  18. @end
  19. @implementation DoubleMapViewController {
  20. GMSMapView *_mapView;
  21. GMSMapView *_boundMapView;
  22. }
  23. + (GMSCameraPosition *)defaultCamera {
  24. return [GMSCameraPosition cameraWithLatitude:37.7847
  25. longitude:-122.41
  26. zoom:5];
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Two map views, second one has its camera target controlled by the first.
  31. CGRect frame = self.view.bounds;
  32. frame.size.height = frame.size.height / 2;
  33. _mapView = [GMSMapView mapWithFrame:frame camera:[DoubleMapViewController defaultCamera]];
  34. _mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
  35. UIViewAutoresizingFlexibleHeight |
  36. UIViewAutoresizingFlexibleBottomMargin;
  37. _mapView.delegate = self;
  38. [self.view addSubview:_mapView];
  39. frame = self.view.bounds;
  40. frame.size.height = frame.size.height / 2;
  41. frame.origin.y = frame.size.height;
  42. _boundMapView =
  43. [GMSMapView mapWithFrame:frame camera:[DoubleMapViewController defaultCamera]];
  44. _boundMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
  45. UIViewAutoresizingFlexibleHeight |
  46. UIViewAutoresizingFlexibleTopMargin;
  47. _boundMapView.settings.scrollGestures = NO;
  48. [self.view addSubview:_boundMapView];
  49. }
  50. - (void)viewWillTransitionToSize:(CGSize)size
  51. withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  52. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  53. CGRect frame = self.view.bounds;
  54. frame.size.height = frame.size.height / 2;
  55. _mapView.frame = frame;
  56. }
  57. - (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position {
  58. GMSCameraPosition *previousCamera = _boundMapView.camera;
  59. _boundMapView.camera = [GMSCameraPosition cameraWithTarget:position.target
  60. zoom:previousCamera.zoom
  61. bearing:previousCamera.bearing
  62. viewingAngle:previousCamera.viewingAngle];
  63. }
  64. @end