ios谷歌地图performselector显示infowindow

时间:2014-05-31 19:30:54

标签: ios google-maps google-maps-sdk-ios

我不确定这是否适用于Google Maps for iOS,但是当模态视图控制器被解除时,我试图刷新标记的打开infoWindow。现在,我只是想让infoWindow手动显示。我添加了一个navigationItem按钮并将坐标发送到选择器:

- (void) dosomething:(id)sender{
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(41.05061, 28.77244);
    GMSMarker *marker = [[GMSMarker alloc]init];
    marker.position = position;
    [self performSelector:@selector(mapView:markerInfoWindow:) withObject:mapView_ withObject:marker];
}

- (UIView *) mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
    NSLog(@"%f, %f", marker.position.latitude, marker.position.longitude);
    InfoWindow *infoWindow = [[InfoWindow alloc]init];
    NSDictionary *thisMarker = [NSDictionary new];
    _thisMarker = thisMarker;
    for (NSDictionary *dic in [MainMarkers sharedInstance].mainMarkers){
        if ([[dic valueForKey:@"latitude"]isEqualToString:@(marker.position.latitude).stringValue] && [[dic valueForKey:@"longitude"]isEqualToString:@(marker.position.longitude).stringValue]) {
            _thisMarker = dic;
        }
    }
    NSLog(@"%@", _thisMarker);
    //...infoWindow setUp
    return infoWindow;
}

日志有效,我发送了指定的坐标,但infoWindow没有显示。如果我点击标记,一切都有效。是否可以这样打开infoWindow?

更新:

在viewWillAppear方法中,我尝试了这个:

- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
if (_thisMarker) {
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[_thisMarker valueForKey:@"latitude"] floatValue], [[_thisMarker valueForKey:@"longitude"] floatValue]);
    GMSMarker *marker = [[GMSMarker alloc]init];
    marker.position = position;
    mapView_.selectedMarker = (GMSMarker*)marker;
    }
}

我将添加我使用infoWindow的自定义视图。如果我添加marker.map = mapView_; infoWindow出现但它没有重新绘制,根据数据(标记图标,标记名称,标记详细信息)重新创建...所以我仍然无法使其工作。

2 个答案:

答案 0 :(得分:1)

可能想试试这个......

[self.mapView setSelectedMarker:marker];

答案 1 :(得分:0)

如果地图上已有标记,您只需要让地图选择它:

self.mapView.selectedMarker = (GMSMarker*)marker;

结果与用户点击标记的结果相同。