Guest User

Untitled

a guest
Jul 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. #define METERS_MILE 1609.344
  2. #define METERS_FEET 3.28084
  3.  
  4. #import "ViewController.h"
  5. #import "../Jetfire_websocket/JFRWebSocket.h"
  6. #import "MyCustomAnnotation.h"
  7.  
  8. @interface ViewController ()
  9. <CLLocationManagerDelegate>
  10. @end
  11.  
  12. @interface ViewController ()<JFRWebSocketDelegate>
  13.  
  14. @property(nonatomic, strong)JFRWebSocket *socket;
  15.  
  16. @end
  17.  
  18. @interface ViewController () <MKMapViewDelegate>
  19. @end
  20.  
  21. @implementation ViewController
  22.  
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view, typically from a nib.
  26.  
  27. self.mapView.delegate = self;
  28.  
  29. // Location services.
  30. [[self mapView] setShowsUserLocation:YES];
  31.  
  32. self.locationManager = [[CLLocationManager alloc] init];
  33.  
  34. [[self locationManager] setDelegate:self];
  35.  
  36.  
  37. // Need to setup the location manager with permission in iOS versions later than ios8.
  38. if ([[self locationManager] respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
  39. [[self locationManager] requestWhenInUseAuthorization];
  40. }
  41.  
  42. [[self locationManager] setDesiredAccuracy:kCLLocationAccuracyBest];
  43. [[self locationManager] startUpdatingLocation];
  44.  
  45. NSLog(@"Custom Annotations start.");
  46. // Custom Annotations.
  47. CLLocationCoordinate2D bryanParkCoordinates = CLLocationCoordinate2DMake(37.785834, -122.406417);
  48. MyCustomAnnotation *bryanParkAnnotation = [[MyCustomAnnotation alloc]initWithTitle:@"Bryant Park" Location:bryanParkCoordinates];
  49. [self.mapView addAnnotation:bryanParkAnnotation];
  50.  
  51. // Simple pin.
  52. MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
  53. [annotation setCoordinate:bryanParkCoordinates];
  54. [annotation setTitle:@"Title"];
  55. [self.mapView addAnnotation:annotation];
  56.  
  57. // Another try.
  58. CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(37.330713, -121.894348);
  59. MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.1);
  60. MKCoordinateRegion region = {coord, span};
  61.  
  62. MKPointAnnotation *newannotation = [[MKPointAnnotation alloc] init];
  63. [newannotation setCoordinate:coord];
  64.  
  65. [self.mapView setRegion:region];
  66. [self.mapView addAnnotation:newannotation];
  67.  
  68. // On your location.
  69. MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
  70. point.coordinate = bryanParkCoordinates;
  71. point.title = @"Where am I?";
  72. point.subtitle = @"I'm here!!!";
  73.  
  74. [self.mapView addAnnotation:point];
  75.  
  76. // Geocoding
  77. self.searchResult.text = @"default text";
  78. [self.searchButton setTitle:@"Search Location Name" forState:(UIControlStateNormal)];
  79.  
  80.  
  81. // websocket connection initialization.
  82. self.socket = [[JFRWebSocket alloc] initWithURL:[NSURL URLWithString:@"ws://localhost:9002"] protocols:@[@"chat",@"superchat"]];
  83. self.socket.delegate = self;
  84. [self.socket connect];
  85.  
  86. // Firebase initialization.
  87. self.ref = [[FIRDatabase database] reference];
  88. }
  89.  
  90. -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
  91. {
  92. // if([annotation isKindOfClass:[MyCustomAnnotation class]])
  93. // {
  94. // MyCustomAnnotation *myLocation = (MyCustomAnnotation *)annotation;
  95. // MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MyCustomAnnotation"];
  96. // if(annotationView == nil)
  97. // annotationView = myLocation.annotationView;
  98. // else
  99. // annotationView.annotation = annotation;
  100. // return annotationView;
  101. // }
  102. // else{
  103. // MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"DETAILPIN_ID"];
  104. // [pinView setAnimatesDrop:YES];
  105. // [pinView setCanShowCallout:NO];
  106. // return pinView;
  107. // //return nil;
  108. // }
  109. if (annotation == mapView.userLocation) return nil;
  110.  
  111. static NSString* Identifier = @"PinAnnotationIdentifier";
  112. MKPinAnnotationView* pinView;
  113. pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:Identifier];
  114.  
  115. if (pinView == nil) {
  116. pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
  117. reuseIdentifier:Identifier];
  118. pinView.canShowCallout = YES;
  119. return pinView;
  120. }
  121. pinView.annotation = annotation;
  122. return pinView;
  123. }
Add Comment
Please, Sign In to add comment