MarkerEventsViewController.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #if !defined(__has_feature) || !__has_feature(objc_arc)
  2. #error "This file requires ARC support."
  3. #endif
  4. #import "SDKDemos/Samples/MarkerEventsViewController.h"
  5. #import <GoogleMaps/GoogleMaps.h>
  6. #import <QuartzCore/QuartzCore.h>
  7. @implementation MarkerEventsViewController {
  8. GMSMapView *mapView_;
  9. GMSMarker *melbourneMarker_;
  10. }
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
  14. longitude:144.966085
  15. zoom:4];
  16. mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  17. GMSMarker *sydneyMarker = [[GMSMarker alloc] init];
  18. sydneyMarker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
  19. sydneyMarker.map = mapView_;
  20. melbourneMarker_ = [[GMSMarker alloc] init];
  21. melbourneMarker_.position = CLLocationCoordinate2DMake(-37.81969, 144.966085);
  22. melbourneMarker_.map = mapView_;
  23. mapView_.delegate = self;
  24. self.view = mapView_;
  25. }
  26. #pragma mark - GMSMapViewDelegate
  27. - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  28. if (marker == melbourneMarker_) {
  29. return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon"]];
  30. }
  31. return nil;
  32. }
  33. - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
  34. // Animate to the marker
  35. [CATransaction begin];
  36. [CATransaction setAnimationDuration:3.f]; // 3 second animation
  37. GMSCameraPosition *camera =
  38. [[GMSCameraPosition alloc] initWithTarget:marker.position
  39. zoom:8
  40. bearing:50
  41. viewingAngle:60];
  42. [mapView animateToCameraPosition:camera];
  43. [CATransaction commit];
  44. // Melbourne marker has a InfoWindow so return NO to allow markerInfoWindow to
  45. // fire. Also check that the marker isn't already selected so that the
  46. // InfoWindow doesn't close.
  47. if (marker == melbourneMarker_ &&
  48. mapView.selectedMarker != melbourneMarker_) {
  49. return NO;
  50. }
  51. // The Tap has been handled so return YES
  52. return YES;
  53. }
  54. @end