¿Cómo agregar un botón en los mapas de Google en iOS?
Soy nuevo en la programación de iOS y he descargado sdk de google maps para iOS y he seguido las instrucciones en su sitio web (como se muestra en este enlace)https://developers.google.com/maps/documentation/ios/start ) y pude obtener el mapa en mi solicitud.
Ahora estoy tratando de agregar un botón en la pantalla en la parte inferior de los mapas de Google para dar una opción al usuario para volver a la pantalla anterior.
Solo sé que UIButton es una subclase de UIView y podemos hacer que aparezca un botón en una vista al convertirla en la vista secundaria de esa clase. Anteriormente, iOS solía usar Google Maps de forma predeterminada por MKMapView y he visto ejemplos en libros y en Internet que muestran capturas de pantalla de aplicaciones donde un botón o un cuadro de texto aparecerían en el mapa. Pero ahora solo arrastrando el botón en el generador de interfaces no ayuda con el SDK de google maps.
Aquí está mi 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
Puedes ver que en las últimas 2 líneas he hecho del botón la subvista de mapview y he intentado mostrarlo. Pero esto no ayudó. Por favor, hágame saber qué es lo que me estoy perdiendo o si hay otra forma de hacerlo utilizando otra función.
Por favor, también revise la captura de pantalla del guión gráfico que he creado para que pueda entender mejor lo que estoy tratando de hacer aquí.
Gracias.