微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Obj-C - Google Maps SDK 获取所选标记的数据?

如何解决Obj-C - Google Maps SDK 获取所选标记的数据?

我正在尝试使用以下代码获取选定标记的数据:

-(void)viewDidLoad {

 NSMutableDictionary *viewParams3 = [NSMutableDictionary new];
     [viewParams3 setValue:@"breweries" forKey:@"view_name"];
     [dioSView viewGet:viewParams3 success:^(AFHTTPRequestOperation *operation,id responSEObject) {
         
         self.breweryLocations = [responSEObject mutablecopy];
      
      
         int index = 0;
         
         for (NSMutableDictionary *brewInfo in self.breweryLocations) {
         
         Nsstring *location = brewInfo[@"address"];
         Nsstring *userNames = brewInfo[@"node_title"];
         Nsstring *firstRemoved = [userNames stringByReplacingOccurrencesOfString:@"'" withString:@""];

          
         Nsstring *userBio = brewInfo[@"body"];
         

          
          CLGeocoder *geocoderFriend = [[CLGeocoder alloc] init];
          [geocoderFriend geocodeAddressstring:location
            completionHandler:^(NSArray* placemarks,NSError* error){
            if (placemarks && placemarks.count > 0) {
           CLPlacemark *topResult = [placemarks objectAtIndex:0];
             MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
      
                
                
                CLLocationCoordinate2D position = placemark.coordinate;
                GMSMarker *marker = [GMSMarker markerWithPosition:position];
                marker.title = firstRemoved;
                marker.icon = [UIImage imageNamed:@"brewIconMax"];
                marker.map = self.mapView;
                marker.userData = self.breweryLocations;
               
                marker.map.selectedMarker.zIndex = index + 1;
                                                                               }
          
          }
                                                        ];
          
          }
      
         
     } failure:^(AFHTTPRequestOperation *operation,NSError *error) {
         NSLog(@"Failure: %@",[error localizedDescription]);
     }];


}

- (BOOL) mapView: (GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{

   self.venueCategory.text = marker.userData[mapView.selectedMarker.zIndex][@"type"];

}

也就是说,这行代码

self.venueCategory.text = marker.userData[mapView.selectedMarker.zIndex][@"type"];

无论我点击哪个标记,都会从数组中的第一个字典中返回数据(zIndex 始终返回为 0)。我似乎无法在任何地方找到正确的代码获取所选标记的数组数据。

知道那条线应该是什么样子吗?

解决方法

我不清楚“类型”是否是啤酒厂位置词典的一个元素,所以我在这里进行一些猜测。

我建议将 marker.userData 设置为 brewInfo 字典,而不是整个 breweryLocations 数组。

marker.userData = brewInfo;

然后从 brewInfo 字典中获取“类型”。

self.venueCategory.text = marker.userData[@"type"];

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?