MapZoomViewController.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #if !defined(__has_feature) || !__has_feature(objc_arc)
  2. #error "This file requires ARC support."
  3. #endif
  4. #import "SDKDemos/Samples/MapZoomViewController.h"
  5. #import <GoogleMaps/GoogleMaps.h>
  6. @implementation MapZoomViewController {
  7. GMSMapView *mapView_;
  8. UITextView *zoomRangeView_;
  9. NSUInteger nextMode_;
  10. }
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868
  14. longitude:151.2086
  15. zoom:6];
  16. mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  17. mapView_.settings.scrollGestures = NO;
  18. self.view = mapView_;
  19. // Add a display for the current zoom range restriction.
  20. zoomRangeView_ = [[UITextView alloc] init];
  21. zoomRangeView_.frame =
  22. CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 0);
  23. zoomRangeView_.text = @"";
  24. zoomRangeView_.textAlignment = NSTextAlignmentCenter;
  25. zoomRangeView_.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.8f];
  26. zoomRangeView_.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  27. [self.view addSubview:zoomRangeView_];
  28. [zoomRangeView_ sizeToFit];
  29. [self didTapNext];
  30. // Add a button toggling through modes.
  31. self.navigationItem.rightBarButtonItem =
  32. [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay
  33. target:self
  34. action:@selector(didTapNext)];
  35. }
  36. - (void)didTapNext {
  37. NSString *label = @"";
  38. float minZoom = kGMSMinZoomLevel;
  39. float maxZoom = kGMSMaxZoomLevel;
  40. switch (nextMode_) {
  41. case 0:
  42. label = @"Default";
  43. break;
  44. case 1:
  45. minZoom = 18;
  46. label = @"Zoomed in";
  47. break;
  48. case 2:
  49. maxZoom = 8;
  50. label = @"Zoomed out";
  51. break;
  52. case 3:
  53. minZoom = 10;
  54. maxZoom = 11.5;
  55. label = @"Small range";
  56. break;
  57. }
  58. nextMode_ = (nextMode_ + 1) % 4;
  59. [mapView_ setMinZoom:minZoom maxZoom:maxZoom];
  60. zoomRangeView_.text =
  61. [NSString stringWithFormat:@"%@ (%.2f - %.2f)", label, mapView_.minZoom, mapView_.maxZoom];
  62. }
  63. @end