我一直在使用Google Maps API for iOS,我正在尝试在获得一系列新职位/位置后重新创建标记的位置。
以下是我的Google地图代码:
- (void)loadView {
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 {
NSLog(@"createmarkers called");
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *lat = [[NSMutableArray alloc]init];
NSMutableArray *lng = [[NSMutableArray alloc]init];
NSMutableArray *markers = [[NSMutableArray alloc]init];
NSMutableArray *businessArray = [[NSMutableArray alloc]init];
for (int x = 0; x < [appDelegate.businessArray count]; x++){
[businessArray addObject: [appDelegate.businessArray objectAtIndex:x] ];
}
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 < [businessArray 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 = [[businessArray objectAtIndex:x]valueForKey:@"name"];
marker.snippet = @"123";
marker.icon = [UIImage imageNamed:@"greenPin.png"];
marker.animated = YES;
marker.map = mapView;
[markers addObject:marker];
}
}
如果我是第一次加载视图,则会创建标记。但是,第二次使用新的lat / long坐标集/数组不会加载。
正在调用loadview方法,[mapView clear];应该调用,但它不会清除mapview上的标记。下一个问题是没有创建新标记,但我怀疑这两个问题都与同一个问题有关。
有关地图视图无法清除的原因的任何提示?提前致谢