MarkersViewController.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #if !defined(__has_feature) || !__has_feature(objc_arc)
  2. #error "This file requires ARC support."
  3. #endif
  4. #import "SDKDemos/Samples/MarkersViewController.h"
  5. #import <GoogleMaps/GoogleMaps.h>
  6. @implementation MarkersViewController {
  7. GMSMarker *_sydneyMarker;
  8. GMSMarker *_melbourneMarker;
  9. }
  10. - (void)viewDidLoad {
  11. [super viewDidLoad];
  12. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
  13. longitude:144.966085
  14. zoom:4];
  15. GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  16. _sydneyMarker = [[GMSMarker alloc] init];
  17. _sydneyMarker.title = @"Sydney";
  18. _sydneyMarker.snippet = @"Population: 4,605,992";
  19. _sydneyMarker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
  20. _sydneyMarker.flat = NO;
  21. _sydneyMarker.rotation = 30.0;
  22. NSLog(@"sydneyMarker: %@", _sydneyMarker);
  23. GMSMarker *australiaMarker = [[GMSMarker alloc] init];
  24. australiaMarker.title = @"Australia";
  25. australiaMarker.position = CLLocationCoordinate2DMake(-27.994401,140.07019);
  26. australiaMarker.appearAnimation = kGMSMarkerAnimationPop;
  27. australiaMarker.flat = YES;
  28. australiaMarker.draggable = YES;
  29. australiaMarker.groundAnchor = CGPointMake(0.5, 0.5);
  30. australiaMarker.icon = [UIImage imageNamed:@"australia"];
  31. australiaMarker.map = mapView;
  32. // Set the marker in Sydney to be selected
  33. mapView.selectedMarker = _sydneyMarker;
  34. self.view = mapView;
  35. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(didTapAdd)];
  36. }
  37. - (void)didTapAdd {
  38. if (_sydneyMarker.map == nil) {
  39. _sydneyMarker.map = (GMSMapView *)self.view;
  40. // _sydneyMarker.rotation += 45.0;
  41. } else {
  42. _sydneyMarker.map = nil;
  43. }
  44. _melbourneMarker.map = nil;
  45. _melbourneMarker = [[GMSMarker alloc] init];
  46. _melbourneMarker.title = @"Melbourne";
  47. _melbourneMarker.snippet = @"Population: 4,169,103";
  48. _melbourneMarker.position = CLLocationCoordinate2DMake(-37.81969, 144.966085);
  49. _melbourneMarker.map = (GMSMapView *)self.view;
  50. }
  51. @end