gpt4 book ai didi

iOS:如何使用自定义信息窗口动态创建 GMSMarker?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:26:52 25 4
gpt4 key购买 nike

我通过for循环创建了GMSMarker,但是GMSMarker不支持标签

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

最佳答案

您可以使用 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;
}

文档

Marker data. You can use this property to associate an arbitrary object with this marker. Google Maps SDK for iOS neither reads nor writes this property. Note that userData should not hold any strong references to any Maps objects, otherwise a loop may be created (preventing ARC from releasing objects).

关于iOS:如何使用自定义信息窗口动态创建 GMSMarker?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27544975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com