Como adicionar um botão nos mapas do Google no iOS?
Eu sou novo no iOS Programming e baixei o google maps sdk para iOS e segui as instruções no site deles (como mostrado neste link)https://developers.google.com/maps/documentation/ios/start ) e foi capaz de obter o mapa na minha aplicação.
Agora eu estou tentando adicionar um botão na tela na parte inferior sobre o Google Maps para dar uma opção para o usuário voltar para a tela anterior.
Eu apenas sei que o UIButton é uma subclasse do UIView e podemos fazer com que um botão apareça em uma visualização tornando-o a sub visão dessa classe. Anteriormente, o iOS costumava usar o Google Maps por padrão pelo MKMapView, e eu vi exemplos em livros e na Internet mostrando capturas de tela de aplicativos em que um botão ou uma caixa de texto apareceria no mapa. Mas agora apenas arrastando o botão no construtor de interface não ajuda com o SDK do google maps.
Aqui está o meu código:
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <GoogleMaps/GoogleMaps.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *btn;
@end
ViewController.m
#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
Você pode ver que nas últimas duas linhas eu fiz o botão a subvisualização do mapview e tentei trazê-lo para frente. Mas isso não ajudou. Por favor, deixe-me saber o que é que estou faltando ou se há outra maneira de fazer isso usando alguma outra função.
Por favor, verifique também o screenshot do storyboard que eu criei para que você possa entender melhor o que estou tentando fazer aqui.
Obrigado.