В настоящее время я работаю с API Карт Google для iOS. Я нарисовал маркеры на картах, но я не знаю, как «обновить» (удалить маркеры и перерисовать новые) маркеры после ввода пользователем новых данных из другого класса. Я пытаюсь вспомнить класс представления карты, как это:Обновить контент на Картах Google iOS
Это код, в другом классе (GetInfoViewController), который выполняется, когда пользователь вводит новые данные
MapViewController *mapVC = [[MapViewController alloc]init];
[mapVC resetMap];
Это то, что находится внутри MapViewController
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.myLocationEnabled = YES;
mapView.settings.myLocationButton = YES;
getpos = [[NSMutableArray alloc]init];
}
- (void)loadView {
lat = [[NSMutableArray alloc]init];
lng = [[NSMutableArray alloc]init];
markers = [[NSMutableArray alloc]init];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude
longitude:locationManager.location.coordinate.longitude zoom:13.2];
mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.delegate = self;
self.view = mapView;
[mapView clear];
[self createMarker];
}
- (void) createMarker {
[lat removeAllObjects];
[lng removeAllObjects];
[markers removeAllObjects];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
for (int x = 0; x < [appDelegate.geocodedLatArrayGlobal count]; x++) {
NSNumber *latCoord = [NSNumber numberWithDouble:[[appDelegate.geocodedLatArrayGlobal objectAtIndex:x]doubleValue]];
[lat addObject: latCoord];
}
for (int x = 0; x < [appDelegate.geocodedLngArrayGlobal count]; x++) {
NSNumber *lngCoord = [NSNumber numberWithDouble:[[appDelegate.geocodedLngArrayGlobal objectAtIndex:x]doubleValue]];
[lng addObject:lngCoord];
}
for (int x = 0; x < [lat count]; x++) {
double latitude =[[lat objectAtIndex:x]doubleValue];
double longitude =[[lng objectAtIndex:x]doubleValue];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(latitude,longitude) ;
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Title"
marker.map = mapView;
[markers addObject:marker];
}
}
-(void)resetMap{
NSLog(@"map reset");
[mapView clear];
[self createMarker];
}
в GetInfoViewController: Изменение содержимого контейнера к MapViewController
MapViewController *viewController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"vc1"];
viewController1.view.frame = self.container.bounds;
[viewController1 willMoveToParentViewController:self];
[self.container addSubview:viewController1.view];
[self addChildViewController:viewController1];
[viewController1 didMoveToParentViewController:self];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.container cache:YES];
[UIView commitAnimations];
Не вызывайте viewDidLoad вручную. – satheeshwaran
я бы назвал loadView? Я уже пытался вызвать как loadView, так и createMarkers, и ничего не обновляет на карте. – Alexyuiop
Когда пользователь что-то обновляет, вызывается mapView clear, а затем снова загружает все ваши маркеры. Это не лучший способ, но мы можем попытаться найти то, что не работает. – satheeshwaran