Google Maps标记未删除iOS [英] Google Maps markers not removing iOS

查看:69
本文介绍了Google Maps标记未删除iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个线程,每10秒获取一次驱动程序的位置,并且想从地图上删除添加的标记,但这是行不通的.

I'm running a thread to fetch drivers location every 10 seconds and want to remove the added markers from the map but it doesn't work..

我的代码:

-(void)APiResponse:(id)returnJson
{        
        [googleMapsDriverPin setMap:nil];
        googleMapsDriverPin = nil;

        NSMutableArray *driverPins = [[NSMutableArray alloc]init];
        for (int x = 0; x < [[returnJson valueForKey:@"drivers"] count]; x++) {
            CLLocation *driverLocations = [[CLLocation alloc]initWithLatitude:[[[[returnJson valueForKey:@"drivers"] objectAtIndex:x] valueForKey:@"driver_latitude"] doubleValue] longitude:[[[[detail valueForKey:@"drivers"] objectAtIndex:x] valueForKey:@"driver_longitude"] doubleValue]];
            [driverPins addObject:driverLocations];
        }

        for (CLLocation *newLocation in driverPins) {
            googleMapsDriverPin = [[GMSMarker alloc] init];
            [googleMapsDriverPin setPosition:newLocation.coordinate];
            [googleMapsDriverPin setAnimated:YES];
            [googleMapsDriverPin setTitle:@"title"];
            [googleMapsDriverPin setSnippet:@"snippet"];
            [googleMapsDriverPin setIcon:[GMSMarker markerImageWithColor:[UIColor blackColor]]];
            [googleMapsDriverPin setMap:googleMaps];
         }
}

它只会每10秒添加一次,并且不会删除,请提供帮助! 谢谢!

It just keeps adding and adding every 10 seconds and not removing, please help! Thanks!

推荐答案

这是一种快速而肮脏的选择,但是如果您希望采用这种方式,则GMSMarker具有userData属性,您可以使用该属性来标记驱动器引脚

Its a kind of quick and dirty option but if you wanted to go that way GMSMarker has a userData property which you could use to tag the driver pins

- (void)apiResponse:(id)returnJson
{        
    for (GMSMarker *pin in self.googleMaps.markers) {
        if (pin.userData == @"Driver Pin"){ 
            pin.map = nil; 
        }
    }

    ...

    for (CLLocation *newLocation in driverPins) {
        googleMapsDriverPin = [[GMSMarker alloc] init];
        ...
        [googleMapsDriverPin setUserData:@"Driver Pin"];
    }
}

更新:

[self.googleMapsView clear];

这篇关于Google Maps标记未删除iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆