0
実際には、マーカーにiconviewを追加して、そのマーカーをタップすると別のアイコンビューに変更します。これはdidTapMarker
デリゲートメソッドでiconviewを追加することで簡単に行うことができます。しかし、別のマーカーを選択したときにデフォルトの表示に変更する方法。ちょうどトグルボタンToggle ButtonのようにGoogle Makerを作成する
- (void)viewDidLoad
{
for(int i=0;i<lat.count;i++)
{
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[lat objectAtIndex:i]doubleValue],[[longit objectAtIndex:i]doubleValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, 60)];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 69, 21)];
label.text = @"Hello";
label.font = [UIFont systemFontOfSize:10];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor colorWithRed:24.0/255.0 green:59.0/255.0 blue:91.0/255.0 alpha:1.0];
label.backgroundColor = [UIColor colorWithRed:177.0/255.0 green:177.0/255.0 blue:177.0/255.0 alpha:1.0];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 21, 69, 38)];
[btn setImage:[UIImage imageNamed:@"map2_"] forState:UIControlStateNormal];
[view addSubview:label];
[view addSubview:btn];
marker.iconView = view;
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = _mapView;
}
}
とあなたはuserData
そのためGMSMarker
のプロパティをすることができます
-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, 60)];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 69, 21)];
label.text = @"Hello";
label.font = [UIFont systemFontOfSize:10];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:32.0/255.0 green:139.0/255.0 blue:58.0/255.0 alpha:1.0];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 21, 69, 38)];
[btn setImage:[UIImage imageNamed:@"map3_"] forState:UIControlStateNormal];
[view addSubview:label];
[view addSubview:btn];
marker.iconView = view;
return YES;
}
のような
didTapMarker
チェックにちょうど方法** didTapMarker **内部で一意にあなたのマーカーを同定し、それに応じてカスタムのものを行います。.. – vaibhav