在iPhone中的Google地图中添加像UISlider或UIButtom这样的子视图

我是iOS编程的新手,对COCOA Touch知之甚less。 我试图在谷歌地图底部的屏幕上添加一个button,让用户可以select回到上一个屏幕。 我只知道UIButtonUIView的子类,我们可以使button出现在视图上,使其成为该类的子视图。 以前,iOS在默认情况下是通过MKMapView使用谷歌地图的,我曾在互联网上的书籍和书籍中看到过一个例子,在地图上显示一个button或一个文本框的应用程序屏幕截图。 但是现在只需在界面生成器中拖动button并不会有帮助。

在MKMapView上的文本框

这是我的代码:

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 

请让我知道如何做到这一点。

谢谢。

在当前视图上进行正常的UI构build,然后添加GMSMapView作为subview (在index 0处)(不要做self.view = mapView;

这是重要的代码:

 mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; [self.view insertSubview:mapView atIndex:0]; 

index 0处插入地图视图将在前面设置其余的对象。

我build议编程创buildbutton不使用storyBoard,我testing了这个“谷歌地图SDK版本:1.4.0.4450”,它的工作。

 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(10, 10, 100, 40); [button setTitle:@"title" forState:UIControlStateNormal]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.279526 longitude:-96.987305 zoom:2]; self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];; self.view = self.mapView; [self.view addSubview:button];