【发布时间】:2016-07-28 09:29:24
【问题描述】:
我想在地图视图中更改用户最近的位置图钉图像。
“在我的项目中,我在地图视图中显示了一些商店位置。位置(纬度,经度)是从 api 获取的。这里我更改了给定的位置图钉图像。它工作正常。但我需要更改地图视图中用户最近的位置图钉图像。我已经获得了从用户当前位置到给定 api 位置的距离详细信息,这些位置低于 5 英里,位置图钉图像需要更改。"
这是我的注释代码:
// 查看用于更改图钉图像的注释委托代码。
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation: (id<MKAnnotation>)annotation
{
[self.annotationCustom_View removeFromSuperview];
[self.annotationCurrentLoc_View removeFromSuperview];
static NSString *identifier = @"myAnnotation";
CustomMapViewAnnotation * annotationView = (CustomMapViewAnnotation *)[self.locationsMap_View dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView)
{
annotationView = [[CustomMapViewAnnotation alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
if([annotation isKindOfClass:[MKUserLocation class]])
{
annotationView.image = [UIImage imageNamed:@"LocationsYour-Current-Location-Icon"]; // User Current Location Image
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
for(int i=0;i<[locations_ArrayList count];i++)
{
MapViewLocationModel *objValue=[locations_ArrayList objectAtIndex:i];
float value = [objValue.kiosk_distance floatValue];
if(value < 5.0)
{
annotationView.image = [UIImage imageNamed:@"LocationsFridge-Location-Icon"]; // Change the pin image which are the below 5.0 miles distance from the user current locations
}
else
{
annotationView.image = [UIImage imageNamed:@"LocationsBlackDot"]; // given api locations pin images
}
}
});
}
}
annotationView.canShowCallout = NO;
return annotationView;
}
这是我的代码。任何人都可以帮助我吗?
【问题讨论】:
标签: ios objective-c mkmapview