Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google maps markerInfowindow delegate not calling ios

I am using Google Maps SDK for iOS app. I need to customize markerinfowindow. I add

1) @interface MapsViewController : UIViewController GMSMapViewDelegate

2) mapView_.delegate = self; in viewdidload and

3)

 - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
            UIView *InfoWindow = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 200)];
            UILabel *nameLabel = [[UILabel alloc]init];
             nameLabel.text = @"hi";
             [InfoWindow addSubview:nameLabel];

    return InfoWindow;
}

but control is not comming in markerInfoWindow.

like image 844
Tahir Mehmood Avatar asked Feb 13 '14 06:02

Tahir Mehmood


3 Answers

I had the same problem - markerInfoWindow wouldn't get called even after setting the delegate. Ended up doing this:

- (BOOL)mapView:(GMSMapView*)mapView didTapMarker:(GMSMarker*)marker
{
  [mapView setSelectedMarker:marker];
  return YES;
}

setSelectedMarker will force a call on markerInfoWindow.

like image 149
etayluz Avatar answered Nov 08 '22 04:11

etayluz


Ok it is solve i add mapView_.delegate = self; before marker making thanks

like image 2
Tahir Mehmood Avatar answered Nov 08 '22 04:11

Tahir Mehmood


To Use markerInfoWindow method for custom Callout, you also need to set its anchor using infoWindowAnchor property.

When you create your marker set the anchor:

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = MARKER_POSITION;
marker.infoWindowAnchor = CGPointMake(0.44f, 0.45f);
marker.icon = [UIImage imageNamed:@"CustomMarkerImageName"];

then create the delegate method.

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
  InfoWindow *view =  [[[NSBundle mainBundle] loadNibNamed:@"InfoWindow" owner:self options:nil] objectAtIndex:0];
  view.name.text = @"Place Name";
  view.description.text = @"Place description";
  view.phone.text = @"123 456 789";
  view.placeImage.image = [UIImage imageNamed:@"customPlaceImage"];
  view.placeImage.transform = CGAffineTransformMakeRotation(-.08);
  return view;
}
like image 2
ArunMak Avatar answered Nov 08 '22 06:11

ArunMak