谷歌地图标记动作

时间:2014-02-27 05:50:10

标签: ios json gmsmapview

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

这是将标记放在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_;

        }

3 个答案:

答案 0 :(得分:1)

根据谷歌地图sdk文档,当用户点击标记时,他们会将渲染图像添加到mapview。所以通常不可能添加按钮添加uiview。但它会将名为“didTapWindowOfMarker”的事件分成三部分。

您可以找到更多信息here

答案 1 :(得分: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")
 }

答案 2 :(得分:0)

快速4 +

采用 GMSMapViewDelegate 并使用此协议

    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
           print("marker tapped:", marker)
           return true
    }