CameraViewController.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/CameraViewController.h"
  16. #import <GoogleMaps/GoogleMaps.h>
  17. @implementation CameraViewController {
  18. GMSMapView *_mapView;
  19. NSTimer *timer;
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.809487
  24. longitude:144.965699
  25. zoom:20
  26. bearing:0
  27. viewingAngle:0];
  28. _mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  29. _mapView.settings.zoomGestures = NO;
  30. _mapView.settings.scrollGestures = NO;
  31. _mapView.settings.rotateGestures = NO;
  32. _mapView.settings.tiltGestures = NO;
  33. self.view = _mapView;
  34. }
  35. - (void)moveCamera {
  36. GMSCameraPosition *camera = _mapView.camera;
  37. float zoom = fmaxf(camera.zoom - 0.1f, 17.5f);
  38. GMSCameraPosition *newCamera =
  39. [[GMSCameraPosition alloc] initWithTarget:camera.target
  40. zoom:zoom
  41. bearing:camera.bearing + 10
  42. viewingAngle:camera.viewingAngle + 10];
  43. [_mapView animateToCameraPosition:newCamera];
  44. }
  45. - (void)viewDidAppear:(BOOL)animated {
  46. [super viewDidAppear:animated];
  47. timer = [NSTimer scheduledTimerWithTimeInterval:1.f/30.f
  48. target:self
  49. selector:@selector(moveCamera)
  50. userInfo:nil
  51. repeats:YES];
  52. }
  53. - (void)viewDidDisappear:(BOOL)animated {
  54. [super viewDidDisappear:animated];
  55. [timer invalidate];
  56. }
  57. - (void)didReceiveMemoryWarning {
  58. [super didReceiveMemoryWarning];
  59. [timer invalidate];
  60. }
  61. @end