0

我在 mapView 上放置标记。标记显示来自 JSON 填充的 NSArray 中的对象。现在,如果用户点击一个标记,它会打开一个信息窗口,其中显示来自数组的两个字段(键)的文本。我需要在信息窗口中放置一个按钮。如果用户点击按钮,则必须打开包含有关所选对象的更多信息的详细视图控制器。

这是将标记放在 mapView 上的代码:

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_;

        }
4

3 回答 3

1

根据谷歌地图 SDK 文档,当用户点击标记时,他们会将渲染图像添加到地图视图中。所以通常不可能像添加uiview一样添加按钮。但它会触发名为“didTapWindowOfMarker”的事件。

您可以在此处找到更多信息。

于 2014-02-27T06:07:20.693 回答
0

接受的答案是正确的,我只是想在 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")
 }
于 2018-04-20T09:28:05.500 回答
0

斯威夫特 4+

采用GMSMapViewDelegate并使用此协议

    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
           print("marker tapped:", marker)
           return true
    }
于 2019-09-20T12:35:29.857 回答