【问题标题】:infowindow not displaying with marker in didTapAtCoordinate method在 didTapAtCoordinate 方法中,信息窗口不显示标记
【发布时间】:2015-01-28 08:32:30
【问题描述】:

我正在尝试同时显示infowindowmarker

代码

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

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

代码:

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


}

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

 [self set_markerOnMap:21.214894 longitude:72.88087];

}

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

【问题讨论】:

    标签: objective-c iphone google-maps ios7 gmsmapview


    【解决方案1】:

    看看这是否有效...

    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [self set_markerOnMap:21.214894 longitude:72.88087];
    }];
    

    【讨论】:

    • 问题的答案应该在您提出建议之前进行测试。单纯的想法不属于答案。
    【解决方案2】:

    因此,正如 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),我将与工程部门合作解决此问题。

    感谢您的报告! =)

    【讨论】:

      猜你喜欢
      • 2016-07-27
      • 2013-09-02
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 2014-10-15
      • 2013-09-13
      • 2016-04-29
      • 1970-01-01
      相关资源
      最近更新 更多