GroundOverlayViewController.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/GroundOverlayViewController.h"
  16. #import <GoogleMaps/GoogleMaps.h>
  17. @interface GroundOverlayViewController ()<GMSMapViewDelegate>
  18. @end
  19. @implementation GroundOverlayViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. CLLocationCoordinate2D southWest = CLLocationCoordinate2DMake(40.712216, -74.22655);
  23. CLLocationCoordinate2D northEast = CLLocationCoordinate2DMake(40.773941, -74.12544);
  24. GMSCoordinateBounds *overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:southWest
  25. coordinate:northEast];
  26. // Choose the midpoint of the coordinate to focus the camera on.
  27. CLLocationCoordinate2D newark = GMSGeometryInterpolate(southWest, northEast, 0.5);
  28. GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:newark
  29. zoom:12
  30. bearing:0
  31. viewingAngle:45];
  32. GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  33. mapView.delegate = self;
  34. // Add the ground overlay, centered in Newark, NJ
  35. GMSGroundOverlay *groundOverlay = [[GMSGroundOverlay alloc] init];
  36. // Image from http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg
  37. groundOverlay.icon = [UIImage imageNamed:@"newark_nj_1922.jpg"];
  38. groundOverlay.tappable = YES;
  39. groundOverlay.position = newark;
  40. groundOverlay.bounds = overlayBounds;
  41. groundOverlay.map = mapView;
  42. self.view = mapView;
  43. }
  44. - (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay {
  45. float opacity = (((float)arc4random()/0x100000000)*0.5f + 0.5f);
  46. ((GMSGroundOverlay *)overlay).opacity = opacity;
  47. }
  48. @end