如何删除一组GMSMarker?

问题描述 投票:0回答:1

我正在使用此代码在GoogleMapView中设置多个注释。

- (void)setDriverAnnotationsWith:(NSMutableArray *)drivers
{
    if (drivers.count == 0)
    {
        return;
    }

    for (NSDictionary *driverAttributes in drivers)
    {
        float latitude = [[driverAttributes objectForKey:@"latitude"]floatValue];
        float longitude = [[driverAttributes objectForKey:@"longitude"]floatValue];
        float angle = [[driverAttributes objectForKey:@"driver_car_direction_angle"]floatValue];

        GMSMarker *driverMarker = [[GMSMarker alloc] init];
        [driverMarker setPosition:CLLocationCoordinate2DMake(latitude, longitude)];
        NSString *carImage = [Utilities getVehicleImage:[[driverAttributes objectForKey:@"car_type"]integerValue]];
        [driverMarker setIcon:[UIImage imageNamed:carImage]];
        driverMarker.rotation = angle;
        driverMarker.map = _googleMapView;
    }
}

而且我在地图上还有其他一些标记。但是,当点击UITableViewCell时,我需要删除从上述函数创建的标记。我该如何实现?您可以提供的任何帮助将不胜感激。

ios objective-c google-maps gmsmapview
1个回答
0
投票

要从地图上删除标记,您可以将GMSMarker地图设置为nil。例如:

driverMarker.map = nil

您可以查看Maps SDK for iOS文档以获取更多信息:https://developers.google.com/maps/documentation/ios-sdk/marker#remove_a_marker

如果要在轻按/触摸UITableViewCell时删除标记,可以使用iOS中的触摸事件。您可以在此处查看文档:https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/handling_touches_in_your_view

您可能还特别阅读了touchesBegan(_:with:)事件:https://developer.apple.com/documentation/uikit/uiresponder/1621142-touchesbegan

© www.soinside.com 2019 - 2024. All rights reserved.