2

I'm using Google Maps SDK to write an app in Xcode and I have markers all over my map showing different locations.

I have a UIPickerView that shows markers depending on which the user selects like so: enter image description here

Snippet of code:

- (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;
        }
    ....
}

Snippet of method to load markers on 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;
    }
}

Google Map's documentation doesn't explain how to detect markers on the map.

Since I'm using a UIPickerView to display certain markers on the map, how do I detect markers on the map to delete them and only show the markers the user selects from the UIPickerView?

The only thing I know to do is to use [mapView clear] but then that would clear everything on the map, even the overlay that I have over the map.

Pangu
  • 3,721
  • 11
  • 53
  • 120
  • Check this post http://stackoverflow.com/questions/21200914/remove-particular-gmsmarker-from-gmsmapview-using-google-map-sdk-in-ios – srinivas n Nov 07 '14 at 23:50
  • thanks for the post, it's pretty much the same issue :)....the only issue I have is, of course, it's not working for me :(...I'm using a loop to generate markers and the OP's code removes just one marker..I'm also confused why the solution says to remove "GMSMarker *currLocMarker = [[GMSMarker alloc] init];" – Pangu Nov 08 '14 at 00:33

0 Answers0