【问题标题】:Google maps marker action谷歌地图标记操作
【发布时间】:2014-02-27 05:50:10
【问题描述】:

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

        }

【问题讨论】:

    标签: ios json gmsmapview


    【解决方案1】:

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

    您可以找到更多信息here

    【讨论】:

    • 谢谢,我已经包含了以下代码,但它从未被调用:-(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker{ NSLog(@"MARKER... .. %@",标记); }
    • 在注释视图中点击时调用。你试过了吗。不要忘记设置代表。 stackoverflow.com/questions/15125158/…
    【解决方案2】:

    接受的答案是正确的,我只是想在 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")
     }
    

    【讨论】:

      【解决方案3】:

      Swift 4+

      采用GMSMapViewDelegate并使用此协议

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

      【讨论】:

        猜你喜欢
        • 2011-07-05
        • 1970-01-01
        • 2013-11-27
        • 2023-03-21
        • 1970-01-01
        • 2015-10-29
        • 2018-04-19
        相关资源
        最近更新 更多