【问题标题】:Issue on MapView iOSMapView iOS 上的问题
【发布时间】:2015-05-21 12:46:56
【问题描述】:

我正在我的应用程序上开发MapView。我显示了my current location and also nearest people locations.,但在这里我的问题是我通过WebServices 获取最近的人位置(latitude and longitude values)。我在MapView 上显示了所有人的位置,但有时人数会在那种情况下增加了我显示的任何我得到人们的纬度和经度值,这个纬度和经度值每 2 秒刷新一次,通过使用这个代码,我在 MapView 上显示引脚。

 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 上显示该人数

下图是我附近有三个会员

我在 MapView 上显示了三个人。但是,每当人们在 MapView 上减少时,我需要显示它的引脚会自动在 MapView 上消失。就像这张图片

上面的图片只有一个图钉,但我需要根据人们的纬度和经度值自动显示。我如何删除不在我位置附近的人。您能否建议我如何修改我的代码以在 MapView 上自动显示增加或减少。谢谢

【问题讨论】:

  • 您也可以删除注释

标签: ios objective-c ios8 mkmapview


【解决方案1】:

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

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];

    }

希望对您有所帮助...!

【讨论】:

  • 它可以工作,但最后一个 pin 不应在 mapview @vidhyanand 上删除
  • 您正在使用位置添加新引脚。那为什么你不希望最后一个别针被删除..!
  • 我正在从服务器端获取纬度和经度值,当我在这种情况下获得空的纬度和经度值时,我必须只显示我当前的位置@Vidhyanand900
  • 检查我更新的答案..!如果您得到空的纬度和经度,我将添加带有当前位置的注释..!
  • 您当前的位置是否存在于 lat 数组中。检查我更新的答案您需要在添加新位置之前删除所有对象 marketLocations 数组。它会工作...一旦检查它..!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-21
  • 1970-01-01
  • 2015-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-16
相关资源
最近更新 更多