2

i am trying to show infowindow and marker both simultaneously.

code

-(void)set_markerOnMap:(double)lat longitude:(double)lon{

    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.title = @"Location selected";
    marker.position = CLLocationCoordinate2DMake(lat, lon);
    marker.snippet = @"Testing";
    marker.icon=[UIImage imageNamed:@"red-pin.png"];
    marker.map = self.MyMapView;

    [self.MyMapView setSelectedMarker:marker];

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self set_markerOnMap:21.214894 longitude:72.88087];
    self.MyMapView.delegate=self;
}

above code is working fine and its showing both infowindow and marker together. but my problem is when i called set_markerOnMap method from didTapAtCoordinate instead of viewDidLoad it does not work and only marker is shown.

code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.MyMapView.delegate=self;


}

- (void) mapView:       (GMSMapView *)  mapView
didTapAtCoordinate:     (CLLocationCoordinate2D)    coordinate{

 [self set_markerOnMap:21.214894 longitude:72.88087];

}

anyone can help me where i am wrong?

Bandish Dave
  • 791
  • 1
  • 7
  • 27

2 Answers2

0

See if this works...

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self set_markerOnMap:21.214894 longitude:72.88087];
}];
i2Fluffy
  • 333
  • 2
  • 12
  • Answers to questions should be tested before you suggest them. Mere ideas don't belong as answers. – TylerH Dec 22 '14 at 18:47
0

So the short term answer, as hinted by i2Fluffy, is the following:

@implementation ViewController {
  GMSMarker *tapMarker;
}

- (void)viewDidLoad {
  [super viewDidLoad];

  GMSMapView *mapView = (GMSMapView*)self.view;
  mapView.delegate = self;

  CLLocationCoordinate2D sydney = CLLocationCoordinate2DMake(-33.868, 151.2086);

  mapView.camera = [GMSCameraPosition cameraWithTarget:sydney zoom:8];

  tapMarker = [GMSMarker markerWithPosition:sydney];
  tapMarker.title = @"Tap Marker";
  tapMarker.map = (GMSMapView*)self.view;
}

-(void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {
  NSLog(@"Tap at (%g,%g)", coordinate.latitude, coordinate.longitude);
  tapMarker.position = coordinate;
  [[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [((GMSMapView*)self.view) setSelectedMarker:tapMarker];
  }];
}

@end

The longer term answer is that this is a bug (gmaps-api-issues/7222) and I'll work with engineering to get this fixed.

Thanks for the report! =)

Brett
  • 2,399
  • 1
  • 17
  • 23