这是我ViewController.m
的代码:到目前为止,我一直在viewDidLoad
的数据库中加载地图标记列表。我想添加一个标记并将其显示在地图上,但标记在我关闭视图并再次打开之前不会显示。
@interface ViewController : UIViewController <GMSMapViewDelegate, CLLocationManagerDelegate>
@property (strong, nonatomic) IBOutlet GMSMapView *mapView;
@end
- (void)viewDidLoad {
[super viewDidLoad];
// Getting My Location
//Instantiate a location object.
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
//Set some parameters for the location object.
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy: kCLLocationAccuracyBest];
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
NSLog(@"created locationManager");
// Google Map View
_mapView.settings.compassButton = YES;
_mapView.padding = UIEdgeInsetsMake(self.topLayoutGuide.length + 10, 0, self.bottomLayoutGuide.length, 0);
/* Setting Up Markers */
self.mapView.delegate = self;
[self addMarkers];
}
调用IB动作(并且肯定会被调用)以添加新标记,但标记不会显示在地图上。我在ViewWillAppear
和其他人中尝试了此操作,但未添加标记。我开始认为标记只能添加到ViewDidLoad
中...这是真的吗?
-(IBAction)unwindtoRoot:(UIStoryboardSegue *)segue {
NSLog(@"unwindToRoot");
//[self addMarkers];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(40.729358, -73.998301);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Kopi Kopi";
marker.map = _mapView;
}