2

我试图同时展示infowindow两者marker

代码

-(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;
}

上面的代码工作正常,它同时infowindow显示marker。但我的问题是当我调用set_markerOnMap方法didTapAtCoordinate而不是 viewDidLoad它不起作用并且只marker显示。

代码:

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


}

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

 [self set_markerOnMap:21.214894 longitude:72.88087];

}

任何人都可以帮助我哪里错了?

4

2 回答 2

0

看看这是否有效...

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self set_markerOnMap:21.214894 longitude:72.88087];
}];
于 2014-12-22T18:11:44.423 回答
0

因此,正如 i2Fluffy 所暗示的,短期答案如下:

@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

长期的答案是这是一个错误(gmaps-api-issues/7222),我将与工程部门合作解决这个问题。

感谢您的报告!=)

于 2015-01-28T00:32:30.490 回答