Ios 谷歌地图标记行动
我正在地图视图上放置标记。这些标记显示了从JSON填充的NSArray中的对象。 现在,如果用户点击一个标记,它会打开一个信息窗口,显示来自数组中两个字段(键)的文本。 我需要的是在信息窗口中放置一个按钮。如果用户点击该按钮,则必须打开包含有关选定对象的更多信息的详细视图控制器 这是在地图视图上放置标记的代码:Ios 谷歌地图标记行动,ios,json,gmsmapview,Ios,Json,Gmsmapview,我正在地图视图上放置标记。这些标记显示了从JSON填充的NSArray中的对象。 现在,如果用户点击一个标记,它会打开一个信息窗口,显示来自数组中两个字段(键)的文本。 我需要的是在信息窗口中放置一个按钮。如果用户点击该按钮,则必须打开包含有关选定对象的更多信息的详细视图控制器 这是在地图视图上放置标记的代码: for ( int i=0;i<[categorias count];i++){ GMSMarker *marker = [[GMSMarker all
for ( int i=0;i<[categorias count];i++){
GMSMarker *marker = [[GMSMarker alloc] init];
double latitud = [[[categorias objectAtIndex:i] objectForKey:@"latitudEmpresa"] doubleValue];
double longitud = [[[categorias objectAtIndex:i] objectForKey:@"longitudEmpresa"]doubleValue];
marker.position = CLLocationCoordinate2DMake(latitud, longitud);
NSString *nombre = [[categorias objectAtIndex:i] objectForKey:@"nombreEmpresa"];
marker.title = nombre;
NSString *direccion = [[categorias objectAtIndex:i] objectForKey:@"direccionEmpresa"];
marker.snippet = direccion;
marker.map = mapView_;
}
for(int i=0;i根据google map sdk文档,当用户点击标记时,他们会将renderd图像添加到mapview中。因此通常不可能将按钮添加到添加uiview中。但它会触发名为“didTapWindowOfMarker”的事件
您可以找到更多信息。公认的答案是正确的,我只想在Swift中添加等效的解决方案
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker)
{
// An Info window is rendered as an image, it will not respond to actions.
print("Info Window Clicked On")
}
Swift 4+
采用GMSMapViewDelegate并使用此协议
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
print("marker tapped:", marker)
return true
}
谢谢,我已经包含了以下代码,但它从未被调用:-(void)mapView:(GMSMapView*)mapView didTapInfoWindowOfMarker:(GMSMarker*)marker{NSLog(@“marker…”,%@),marker);}当您在注释视图中点击时它被调用。您尝试过了吗?别忘了设置委托。