Remove particular GMSMarker from GMSMapview using Google Map sdk in ios

后端 未结 9 3159
-上瘾入骨i
-上瘾入骨i 2021-02-19 23:18

I am integrating google maps sdk. Its all work fine. But how to remove particular Marker(Pin Point) when second will appear.(I am not using Mapkit)

I want the following:

相关标签:
9条回答
  • 2021-02-20 00:13

    When you tap on specific marker this will remove that marker

    - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {
    
        marker.map = nil;
        return YES;
    }
    
    0 讨论(0)
  • 2021-02-20 00:15

    I made like this:

    GMSMarker *myMarker;
    
    - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
    {
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            if (myMarker) {
                myMarker.map = nil;
                myMarker = nil;
            }
            myMarker = [[GMSMarker alloc] init];
            myMarker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
            myMarker.title = @"title";
            myMarker.map = mapView_;
        }];
    }
    

    and worked well for me !

    0 讨论(0)
  • 2021-02-20 00:15

    In case you have different markers, and you want to remove only specific markers from the map, then you have to hold that marker(s) object.

    say if you have 
    var removableMarkers: [GMSMarker]?
    
    you have to append those markers in the above array when adding markers to map
    
    Now, when you want to remove those markers:
      _ = self.removableMarkers.map({
                $0.map = nil
            })
    self.RemovableMarkers = []
    

    That's it!

    0 讨论(0)
提交回复
热议问题