Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. #import <UIKit/UIKit.h>
  2. #import <MapKit/MapKit.h>
  3. #import <GoogleMaps/GoogleMaps.h>
  4.  
  5.  
  6. @interface ViewController : UIViewController
  7.  
  8. @property (weak, nonatomic) IBOutlet UIButton *btn;
  9.  
  10.  
  11. @end
  12.  
  13. #import "ViewController.h"
  14. #import <MapKit/MapKit.h>
  15. #import <GoogleMaps/GoogleMaps.h>
  16. #import <CoreLocation/CoreLocation.h>
  17.  
  18.  
  19. @interface ViewController ()
  20.  
  21. @end
  22.  
  23. @implementation ViewController
  24. {
  25. GMSMapView *mapView_;
  26. }
  27.  
  28. - (void)viewDidLoad
  29. {
  30. [super viewDidLoad];
  31. // Do any additional setup after loading the view, typically from a nib.
  32. }
  33.  
  34. - (void)didReceiveMemoryWarning
  35. {
  36. [super didReceiveMemoryWarning];
  37. // Dispose of any resources that can be recreated.
  38. }
  39.  
  40. - (void)loadView
  41. {
  42. CLLocationManager *locationManager = [[CLLocationManager alloc] init];
  43. locationManager.distanceFilter = kCLDistanceFilterNone;
  44.  
  45. locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
  46. [locationManager startUpdatingLocation];
  47.  
  48. //Latitude and longitude of the current location of the device.
  49. double lati = locationManager.location.coordinate.latitude;
  50. double longi = locationManager.location.coordinate.longitude;
  51. NSLog(@"Latitude = %f", lati);
  52. NSLog(@"Longitude = %f", longi);
  53.  
  54. CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:lati longitude:longi];
  55.  
  56. // Create a GMSCameraPosition that tells the map to display the coordinate
  57.  
  58. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lati
  59. longitude:longi
  60. zoom:11.5];
  61.  
  62. mapView_ = [GMSMapView mapWithFrame:[[UIScreen mainScreen] bounds] camera:camera];
  63. mapView_.myLocationEnabled = YES;
  64. self.view = mapView_;
  65.  
  66. // Creates a marker in the center of the map.
  67. GMSMarker *marker = [[GMSMarker alloc] init];
  68. marker.position = CLLocationCoordinate2DMake(lati, longi);
  69. marker.title = @"It's Me";
  70. marker.snippet = @"My Location";
  71. marker.map = mapView_;
  72.  
  73. [mapView_ addSubview:_btn];
  74. [mapView_ bringSubviewToFront:_btn];
  75.  
  76. }
  77. @end
  78.  
  79. UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  80. button.frame = CGRectMake(mapView_.bounds.size.width - 110, mapView_.bounds.size.height - 30, 100, 20);
  81. button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
  82. [button setTitle:@"Button" forState:UIControlStateNormal];
  83. [mapView_ addSubview:button];
  84.  
  85. [self.view addSubview: mapView_];
  86.  
  87. self.view = mapView_;
  88.  
  89. mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
  90. mapView_.myLocationEnabled = YES;
  91. [self.view insertSubview:mapView_ atIndex:0];
  92.  
  93. mapView_ = [GMSMapView mapWithFrame:_mapHolder.bounds camera:camera];
  94. mapView_.myLocationEnabled = YES;
  95. [_mapHolder insertSubview:mapView_ atIndex:0];
  96.  
  97. -(void) viewWillAppear:(BOOL)animated
  98. {
  99. locationButton = [UIButton buttonWithType:UIButtonTypeCustom];
  100. locationButton.frame = CGRectMake(0, 30, self.view.frame.size.width/6, self.view.frame.size.height/6);
  101. [locationButton setImage:[UIImage imageNamed:@"location_enabled.png"] forState:UIControlStateNormal];
  102. [self.view addSubview:locationButton];
  103. }
  104.  
  105. let mapButton:UIButton = UIButton(frame: CGRect(x:self.view.bounds.width-50, y: 20, width: 40, height: 40)) //Swfit 5
  106. mapButton.backgroundColor = UIColor.clear
  107. mapButton.setImage(UIImage(named: "list"), for: UIControl.State.normal)
  108. mapButton.setImage(UIImage(named: "map"), for: UIControl.State.selected)
  109. mapButton.addTarget(self, action:#selector(self.mapListClicked), for: .touchUpInside)
  110. self.view.addSubview(mapButton)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement