【发布时间】:2012-08-31 07:36:48
【问题描述】:
我对 mapView 中的注释有一些问题。让我们看一下我的要求。
我想让用户选择会议地点。
有两种选择。
1) 我应该列出附近的数据
或者
2) 他可以将图钉拖放到任何他想要的地方!
为此,我创建了一个细分。 附近数据的第一个索引 和 放置图钉的第二个索引。
对于第一个选项(“附近”),我需要从卖家位置、买家位置以及卖家和买家之间的中点获取附近的数据。所以我调用google api并通过传递纬度和经度三次来获取数据。第一次获取数据时没有问题。我的数组填满了所有数据(包括 3 个响应),并且引脚颜色也会根据要求发生变化。
买家(红色) 卖家(紫色) 中点(绿色)
现在,当我单击放置图钉时,所有数据都会从数组中删除,并且会在地图上放置一个图钉。
到现在为止它工作正常!
但是当您再次单击“附近”时,问题就开始了!毫无疑问,它可以为我提供我想要的数据,但不会保留别针颜色。
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([segmentND selectedSegmentIndex]==0) {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* BridgeAnnotationIdentifier = @"bridgeAnnotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)
[myMapView dequeueReusableAnnotationViewWithIdentifier:BridgeAnnotationIdentifier];
if (!pinView)
{
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease];
switch (self.pinColor) {
case 0:
{
customPinView.pinColor = MKPinAnnotationColorPurple;
}
break;
case 1:
{
customPinView.pinColor = MKPinAnnotationColorRed;
}
break;
case 2:
{
customPinView.pinColor = MKPinAnnotationColorGreen;
}
break;
default:
break;
}
customPinView.canShowCallout = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
return customPinView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
else {
// Code of dragging dropping pin. It works Fine.s
}
}
我附上image 以获得更多想法。
请给我解决方案或任何其他方式来实现它。 记住 Pin 颜色是区分卖方买方和中点的必要条件!
【问题讨论】:
-
只需检查您的开关条件,即控制进入其中或不使用断点
-
self.pinColor 有什么价值?
标签: iphone objective-c xcode google-maps mkmapview