如何解决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 举报,一经查实,本站将立刻删除。