I use the Google Maps SDK to write an application in Xcode, and I have markers all over my map showing different locations.
I have a UIPickerView that shows markers, depending on which user selects like this: 
Code snippet:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { switch (row) { case 0: // Display no marker flags { .... } break; case 1: // Display vendor marker flags { if (isSelectedVendors == NO) { // Mark item as selected in picker list isSelectedVendors = YES; [self addVendorMarkersToMap]; } break; } .... }
A fragment of the method for loading markers on a map:
- (void)addVendorMarkersToMap { // Add coordinates to know where to place markers NSArray *coords = [ [NSArray alloc] initWithObjects: ...]; // Loop through all the coordinates and mark it on the map for (int i = 0; i < [coords count]; i = i + 2) { GMSMarker *marker = [ [GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake([ [coords objectAtIndex:i] floatValue], [ [coords objectAtIndex: (i + 1)] floatValue]); marker.appearAnimation = kGMSMarkerAnimationPop; marker.icon = [UIImage imageNamed:@"vendors.png"]; marker.map = mapView; } }
The Google Map documentation does not explain how to detect markers on a map.
Since I use UIPickerView to display specific markers on a map, how do I detect markers on a map to remove them and show only the markers that the user selects from UIPickerView?
The only thing I know is to use [mapView clear] , but then it will clear everything on the map, even the overlay that I have on the map.
ios objective-c xcode google-maps
Pangu
source share