MarkerInfoWindowViewController.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/MarkerInfoWindowViewController.h"
  5. #import <GoogleMaps/GoogleMaps.h>
  6. @interface MarkerInfoWindowViewController ()<GMSMapViewDelegate>
  7. @end
  8. @implementation MarkerInfoWindowViewController {
  9. GMSMarker *_sydneyMarker;
  10. GMSMarker *_melbourneMarker;
  11. GMSMarker *_brisbaneMarker;
  12. UIView *_contentView;
  13. }
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-37.81969
  17. longitude:144.966085
  18. zoom:4];
  19. GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  20. _sydneyMarker = [[GMSMarker alloc] init];
  21. _sydneyMarker.title = @"Sydney";
  22. _sydneyMarker.snippet = @"Population: 4,605,992";
  23. _sydneyMarker.position = CLLocationCoordinate2DMake(-33.8683, 151.2086);
  24. _sydneyMarker.map = mapView;
  25. NSLog(@"sydneyMarker: %@", _sydneyMarker);
  26. _melbourneMarker.map = nil;
  27. _melbourneMarker = [[GMSMarker alloc] init];
  28. _melbourneMarker.title = @"Melbourne";
  29. _melbourneMarker.snippet = @"Population: 4,169,103";
  30. _melbourneMarker.position = CLLocationCoordinate2DMake(-37.81969, 144.966085);
  31. _melbourneMarker.map = mapView;
  32. NSLog(@"melbourneMarker: %@", _melbourneMarker);
  33. _brisbaneMarker.map = nil;
  34. _brisbaneMarker = [[GMSMarker alloc] init];
  35. _brisbaneMarker.title = @"Brisbane";
  36. _brisbaneMarker.snippet = @"Population: 2,189,878";
  37. _brisbaneMarker.position = CLLocationCoordinate2DMake(-27.4710107, 153.0234489);
  38. _brisbaneMarker.map = mapView;
  39. NSLog(@"brisbaneMarker: %@", _brisbaneMarker);
  40. _contentView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"aeroplane"]];
  41. mapView.delegate = self;
  42. self.view = mapView;
  43. }
  44. #pragma mark GMSMapViewDelegate
  45. - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  46. if (marker == _sydneyMarker) {
  47. return _contentView;
  48. }
  49. return nil;
  50. }
  51. - (UIView *)mapView:(GMSMapView *)mapView markerInfoContents:(GMSMarker *)marker {
  52. if (marker == _brisbaneMarker) {
  53. return _contentView;
  54. }
  55. return nil;
  56. }
  57. @end