我一直在使用适用于 iOS 的 Google Maps API,并且在获得一系列新位置/位置后,我试图重新创建标记的位置。
这是我的谷歌地图代码:
- (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];
}
}
如果我第一次加载视图,则会创建标记。但是,第二次使用新的纬度/经度坐标集/数组不会加载。
正在调用 loadview 方法,并且 [mapView clear]; 应该调用,但它不会清除地图视图上的标记。下一个问题是没有创建新标记,但我怀疑这两个问题与同一件事有关。
关于为什么地图视图无法清除的任何提示?提前致谢