我正在尝试同时展示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];
}
任何人都可以在我错的地方帮助我?
答案 0 :(得分:0)
看看这是否有效......
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self set_markerOnMap:21.214894 longitude:72.88087];
}];
答案 1 :(得分: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),我将与工程部门合作以解决此问题。
感谢您的举报! =)