我正在制作一个使用 GMSMapView 的 iPhone 应用程序,并且我希望能够在地图顶部添加一个工具栏。这是我的代码:
#import "MapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface MapViewController ()
@end
@implementation MapViewController
{
GMSMapView *mapView_;
id<GMSMarker> myMarker;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)back:(id)sender
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
// You don't need to modify the default initWithNibName:bundle: method.
- (void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:30.616083 longitude:-96.338908 zoom:13];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.delegate = self;
self.view = mapView_;
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = CLLocationCoordinate2DMake(30.616083, -96.338908);
options.title = @"College Station";
options.snippet = @"Texas";
[mapView_ addMarkerWithOptions:options];
}
#pragma mark - GMSMapViewDelegate
- (void)mapView:(GMSMapView *)mapView
didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
[myMarker remove];
NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
GMSMarkerOptions *marker = [[GMSMarkerOptions alloc] init];
marker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
marker.title = @"Tap Event";
// (icon for marker) marker.icon = [UIImage imageNamed:@"house"];
myMarker = [mapView_ addMarkerWithOptions:marker];
}
@end
在我的故事板中,我有一个工具栏,但我不知道如何让它显示在 GMSMapView 上。我是 iOS 新手,已经在网上搜索过解决方案,但 GMSMapView 没有任何运气。