PanoramaViewController.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/PanoramaViewController.h"
  16. #import <GoogleMaps/GoogleMaps.h>
  17. static CLLocationCoordinate2D kPanoramaNear = {40.761388, -73.978133};
  18. static CLLocationCoordinate2D kMarkerAt = {40.761455, -73.977814};
  19. @interface PanoramaViewController () <GMSPanoramaViewDelegate>
  20. @end
  21. @implementation PanoramaViewController {
  22. GMSPanoramaView *_view;
  23. BOOL _configured;
  24. UILabel *_statusLabel;
  25. }
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. _view = [GMSPanoramaView panoramaWithFrame:CGRectZero
  29. nearCoordinate:kPanoramaNear];
  30. _view.backgroundColor = [UIColor grayColor];
  31. _view.delegate = self;
  32. self.view = _view;
  33. // Add status label, initially hidden.
  34. _statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 30)];
  35. _statusLabel.alpha = 0.0f;
  36. _statusLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  37. _statusLabel.backgroundColor = [UIColor blueColor];
  38. _statusLabel.textColor = [UIColor whiteColor];
  39. _statusLabel.textAlignment = NSTextAlignmentCenter;
  40. [_view addSubview:_statusLabel];
  41. }
  42. #pragma mark - GMSPanoramaDelegate
  43. - (void)panoramaView:(GMSPanoramaView *)panoramaView
  44. didMoveCamera:(GMSPanoramaCamera *)camera {
  45. NSLog(@"Camera: (%f,%f,%f)",
  46. camera.orientation.heading, camera.orientation.pitch, camera.zoom);
  47. }
  48. - (void)panoramaView:(GMSPanoramaView *)view
  49. didMoveToPanorama:(GMSPanorama *)panorama {
  50. if (!_configured) {
  51. GMSMarker *marker = [GMSMarker markerWithPosition:kMarkerAt];
  52. marker.icon = [GMSMarker markerImageWithColor:[UIColor purpleColor]];
  53. marker.panoramaView = _view;
  54. CLLocationDegrees heading = GMSGeometryHeading(kPanoramaNear, kMarkerAt);
  55. _view.camera =
  56. [GMSPanoramaCamera cameraWithHeading:heading pitch:0 zoom:1];
  57. _configured = YES;
  58. }
  59. }
  60. - (void)panoramaViewDidStartRendering:(GMSPanoramaView *)panoramaView {
  61. _statusLabel.alpha = 0.8f;
  62. _statusLabel.text = @"Rendering";
  63. }
  64. - (void)panoramaViewDidFinishRendering:(GMSPanoramaView *)panoramaView {
  65. _statusLabel.alpha = 0.0f;
  66. }
  67. @end