Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <UIKit/UIKit.h>
- #import <MapKit/MapKit.h>
- #import <GoogleMaps/GoogleMaps.h>
- @interface ViewController : UIViewController
- @property (weak, nonatomic) IBOutlet UIButton *btn;
- @end
- #import "ViewController.h"
- #import <MapKit/MapKit.h>
- #import <GoogleMaps/GoogleMaps.h>
- #import <CoreLocation/CoreLocation.h>
- @interface ViewController ()
- @end
- @implementation ViewController
- {
- GMSMapView *mapView_;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)loadView
- {
- CLLocationManager *locationManager = [[CLLocationManager alloc] init];
- locationManager.distanceFilter = kCLDistanceFilterNone;
- locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
- [locationManager startUpdatingLocation];
- //Latitude and longitude of the current location of the device.
- double lati = locationManager.location.coordinate.latitude;
- double longi = locationManager.location.coordinate.longitude;
- NSLog(@"Latitude = %f", lati);
- NSLog(@"Longitude = %f", longi);
- CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:lati longitude:longi];
- // Create a GMSCameraPosition that tells the map to display the coordinate
- GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:lati
- longitude:longi
- zoom:11.5];
- mapView_ = [GMSMapView mapWithFrame:[[UIScreen mainScreen] bounds] camera:camera];
- mapView_.myLocationEnabled = YES;
- self.view = mapView_;
- // Creates a marker in the center of the map.
- GMSMarker *marker = [[GMSMarker alloc] init];
- marker.position = CLLocationCoordinate2DMake(lati, longi);
- marker.title = @"It's Me";
- marker.snippet = @"My Location";
- marker.map = mapView_;
- [mapView_ addSubview:_btn];
- [mapView_ bringSubviewToFront:_btn];
- }
- @end
- UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- button.frame = CGRectMake(mapView_.bounds.size.width - 110, mapView_.bounds.size.height - 30, 100, 20);
- button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
- [button setTitle:@"Button" forState:UIControlStateNormal];
- [mapView_ addSubview:button];
- [self.view addSubview: mapView_];
- self.view = mapView_;
- mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
- mapView_.myLocationEnabled = YES;
- [self.view insertSubview:mapView_ atIndex:0];
- mapView_ = [GMSMapView mapWithFrame:_mapHolder.bounds camera:camera];
- mapView_.myLocationEnabled = YES;
- [_mapHolder insertSubview:mapView_ atIndex:0];
- -(void) viewWillAppear:(BOOL)animated
- {
- locationButton = [UIButton buttonWithType:UIButtonTypeCustom];
- locationButton.frame = CGRectMake(0, 30, self.view.frame.size.width/6, self.view.frame.size.height/6);
- [locationButton setImage:[UIImage imageNamed:@"location_enabled.png"] forState:UIControlStateNormal];
- [self.view addSubview:locationButton];
- }
- let mapButton:UIButton = UIButton(frame: CGRect(x:self.view.bounds.width-50, y: 20, width: 40, height: 40)) //Swfit 5
- mapButton.backgroundColor = UIColor.clear
- mapButton.setImage(UIImage(named: "list"), for: UIControl.State.normal)
- mapButton.setImage(UIImage(named: "map"), for: UIControl.State.selected)
- mapButton.addTarget(self, action:#selector(self.mapListClicked), for: .touchUpInside)
- self.view.addSubview(mapButton)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement