关于MapView iOS的问题

关于MapView iOS的问题,ios,objective-c,ios8,mkmapview,Ios,Objective C,Ios8,Mkmapview,我正在我的应用程序上开发MapView。我显示了我的当前位置和最近的人员位置。但我的问题是,我通过Web服务获取最近的人员位置纬度和经度值。我在MapView上显示了所有人员位置,但有时在我显示的情况下,人员数量会增加无论我得到什么样的纬度和经度值,这个纬度和经度值每2秒刷新一次,通过使用此代码,我在MapView上显示PIN for (int y = 0; y <[lat count]; y++) { NSLog(@"MapView "); m

我正在我的应用程序上开发MapView。我显示了我的当前位置和最近的人员位置。但我的问题是,我通过Web服务获取最近的人员位置纬度和经度值。我在MapView上显示了所有人员位置,但有时在我显示的情况下,人员数量会增加无论我得到什么样的纬度和经度值,这个纬度和经度值每2秒刷新一次,通过使用此代码,我在MapView上显示PIN

 for (int y = 0; y <[lat count]; y++)
    {
        NSLog(@"MapView ");

        marketAnnotation = [[MKPointAnnotation alloc]init];
        annotationCoord.latitude = [[lat objectAtIndex:y]floatValue];
        annotationCoord.longitude =[[lon objectAtIndex:y]floatValue];
        marketAnnotation.coordinate = annotationCoord;
        [self.mapView addAnnotation:marketAnnotation];
        [marketLocations addObject:marketAnnotation];

        [mapView reloadInputViews];

    }
但我希望在人数减少时显示,我只需要在MapView上显示该人数

下图是我身边有三名成员

到目前为止,我在地图视图上显示了三个人。但是我需要在地图视图上显示任何人减少的时候,它会自动在地图视图上消失。如图所示


上面的图片只有一个pin码,但是我需要根据人的纬度和经度值自动显示。如何删除不在我所在位置附近的人。您能建议我如何修改代码,使其在MapView上自动显示为递增或递减。谢谢您

在加载新位置之前,您需要删除MapView中旧位置的所有注释

for (id<MKAnnotation> annotation in mapView.annotations) 
    {
        if ([annotation isKindOfClass:[MKPointAnnotation class]]) 
        {
            [mapView removeAnnotation:annotation];
        }
    }

//If empty locations then display current location

[marketLocations removeAllObjects];

if([lat count]==0)
{

            marketAnnotation = [[MKPointAnnotation alloc]init];
            annotationCoord.latitude = currentLocationLatitude;
            annotationCoord.longitude =currentLocationLongitude;
            marketAnnotation.coordinate = annotationCoord;
            [self.mapView addAnnotation:marketAnnotation];
            [marketLocations addObject:marketAnnotation];
            [mapView reloadInputViews];

}
for (int y = 0; y <[lat count]; y++)
    {
        NSLog(@"MapView ");

        marketAnnotation = [[MKPointAnnotation alloc]init];
        annotationCoord.latitude = [[lat objectAtIndex:y]floatValue];
        annotationCoord.longitude =[[lon objectAtIndex:y]floatValue];
        marketAnnotation.coordinate = annotationCoord;
        [self.mapView addAnnotation:marketAnnotation];
        [marketLocations addObject:marketAnnotation];

        [mapView reloadInputViews];

    }

希望它能帮助你

您也可以删除注释,但在mapview@Vidhya上不应删除最后一个管脚,并且您正在使用位置添加新管脚。那你为什么不想删除最后一个pin呢。。!我从服务器端获取纬度和经度值,在这种情况下获取空纬度和经度值时,我必须只显示我的当前位置@vidhyanand900检查我的更新答案。。!如果纬度和经度为空,我将添加当前位置的注释。。!您的当前位置是否存在于lat数组中。检查我的更新答案在添加新位置之前,您需要删除所有对象marketLocations数组。它会工作…一旦检查它。。!