Obj-C - Google Maps SDK 获取所选标记的数据?
Obj-C - Google Maps SDK get data for selected marker?
我正在尝试使用以下代码获取所选标记的数据:
-(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"];
returns 来自数组中第一个字典的数据,无论我点击哪个标记(zIndex 始终返回为 0)。我似乎无法在任何地方找到正确的代码来获取所选标记的数组数据。
知道该行应该是什么样子吗?
我不清楚“类型”是否是啤酒厂位置字典的一个元素,所以我在这里进行一些猜测。
我建议将 marker.userData
设置为 brewInfo
字典,而不是整个 breweryLocations
数组。
marker.userData = brewInfo;
然后从 brewInfo
字典中获取“类型”。
self.venueCategory.text = marker.userData[@"type"];
我正在尝试使用以下代码获取所选标记的数据:
-(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"];
returns 来自数组中第一个字典的数据,无论我点击哪个标记(zIndex 始终返回为 0)。我似乎无法在任何地方找到正确的代码来获取所选标记的数组数据。
知道该行应该是什么样子吗?
我不清楚“类型”是否是啤酒厂位置字典的一个元素,所以我在这里进行一些猜测。
我建议将 marker.userData
设置为 brewInfo
字典,而不是整个 breweryLocations
数组。
marker.userData = brewInfo;
然后从 brewInfo
字典中获取“类型”。
self.venueCategory.text = marker.userData[@"type"];