【问题标题】:iOS: How to dynamically create GMSMarker with custom info window?iOS:如何使用自定义信息窗口动态创建 GMSMarker?
【发布时间】:2014-12-18 11:00:31
【问题描述】:

我通过for循环创建GMSMarker,但是GMSMarker不支持tag

for(int i=0;i<[self.shopDetailArray count];i++)
    {
        SHShopLocator *shop = [self.shopDetailArray objectAtIndex:i];

        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = CLLocationCoordinate2DMake(22.2783, 114.1589);
        marker.icon = [UIImage imageNamed:@"StoreLocator_pin"];
        marker.infoWindowAnchor = CGPointMake(0.3, 0.4);
        marker.map = self.map;
    }

那么在设置自定义 markerInfoWindow 时如何识别每个标记?

  - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker

【问题讨论】:

    标签: ios dictionary marker


    【解决方案1】:

    您可以使用GMSMarker 的属性userData。您可以存储每个标记的标识符!

    示例

    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.userData = @{@"marker_id":[NSNumber numberWithInt:12]};
    

    在以下条件下检索其值:

    - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
    {
        NSNumber *number = [marker.userData objectForKey:@"marker_id"];
    
        return mapView;
    }
    

    文档

    标记数据。您可以使用此属性来关联任意 带有此标记的对象。适用于 iOS 的 Google Maps SDK 既不读取也不读取 写入此属性。请注意,userData 不应持有任何强 对任何 Maps 对象的引用,否则可能会创建循环 (防止 ARC 释放对象)。

    【讨论】:

    • 能否请您展示如何在 swift 中使用它,因为它会在 swift 中保持崩溃,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-10
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    相关资源
    最近更新 更多