我目前正在使用Google Maps API for 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的东西时清除,然后再次加载所有标记。这不是最好的方法,但我们可以尝试找到什么不起作用。 – satheeshwaran