gpt4 book ai didi

ios - 有没有一种有效的方法来创建大量 GMSMarker 对象?

转载 作者:行者123 更新时间:2023-11-28 21:55:20 25 4
gpt4 key购买 nike

我在谷歌地图上使用了叠加层,如图所示:

enter image description here

我在右上角有一个 UIButton 按钮,它使用 UIPickerView 过滤标记。

根据选择,我创建了 X 个标记并将其放置在 map 上的适当位置。

我遇到的问题是必须手动执行此操作:

GMSMarker *marker1 = [ [GMSMarker alloc] init];
GMSMarker *marker2 = [ [GMSMarker alloc] init];
GMSMarker *marker3 = [ [GMSMarker alloc] init];
GMSMarker *marker4 = [ [GMSMarker alloc] init];

....

有没有更快更有效的方法来创建 X 数量的 GMSMarker 而无需重复代码,最好是 for 循环?

最佳答案

将所有标记添加到一个数组(coordinatesArray)中。

NSArray *coordinatesArray = ......;

然后

for(int counter=0; counter<[coordinatesArray count]; counter++)
{
GMSMarker *marker = [[GMSMarker alloc] init];

//----Below line is just an example, you'll get lat , lng from the array like the way.
marker.position=CLLocationCoordinate2DMake([coordinatesArray objectAtIndex:counter]);

marker.map = mapView_;
}

希望对您有所帮助。

关于ios - 有没有一种有效的方法来创建大量 GMSMarker 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26799308/

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