0
我想添加多個信息窗口,以便在出標記的同時出現。 如何實現這個?如何顯示GMS mapView的多個信息窗口?
這是我的代碼添加多個標記並添加infoWindow?
for (int i = 0 ; i < jsonDataDict.count; i ++) {
NSDictionary *newDict = [jsonDataDict objectAtIndex:i ];
double latitude = [[newDict valueForKey:@"lat"]doubleValue];
double longitute = [[newDict valueForKey:@"lng"]doubleValue];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(latitude, longitute);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
nameOfPlace = [newDict valueForKey:@"name"];
// distanceOfPlace = [newDict valueForKey:@"distance"];
marker.icon = [self image:[UIImage imageNamed:@"pinPopoye.png"] scaledToSize:CGSizeMake(75.0f, 60.0f)];
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.infoWindowAnchor = CGPointMake(1.1, 0.70);
marker.map = self.mapView;
[self.mapView setSelectedMarker:marker];
//[self mapView:self.mapView markerInfoWindow:marker];
}
}
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 25)];
customView.backgroundColor = [UIColor colorWithRed:71.0/255.0 green:65.0/255.0 blue:65.0/255.0 alpha:0.8];
customView.layer.cornerRadius = 5;
customView.layer.masksToBounds = YES;
nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 10)];
nameLabel.text = nameOfPlace;
nameLabel.textColor = [UIColor whiteColor];
nameLabel.textAlignment = NSTextAlignmentCenter;
nameLabel.font = [UIFont systemFontOfSize:8.0];
[customView addSubview:nameLabel];
distanceLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 12, 60, 10)];
distanceLabel.text = distanceOfPlace;
distanceLabel.textColor = [UIColor whiteColor];
distanceLabel.textAlignment = NSTextAlignmentCenter;
distanceLabel.font = [UIFont systemFontOfSize:8.0];
[customView addSubview:distanceLabel];
return customView;
}
作爲每谷歌文檔,被稱爲信息窗口時的標記物是即將成爲選擇 – YaBoiSandeep
它看起來像在Objective-C的信息窗口不能直接控制除內容。請參閱[信息窗口](https://developers.google.com/maps/documentation/ios-sdk/marker#info_windows)。還明確表示「一次只顯示一個信息窗口」。所以我想不能有多個窗口的iOS。 – gerardnimo
@gerardnimo - 那麼我怎樣才能爲每個標記顯示不同的標籤? –