每个经纬度谷歌地图ios的markerinfowindow
我有经纬度和从API获得的其他信息,但我想动态显示每个经纬度谷歌地图ios的markerinfowindow,ios,google-maps,gmsmapview,Ios,Google Maps,Gmsmapview,我有经纬度和从API获得的其他信息,但我想动态显示markerinfowindow,并显示一些信息,如名称和编号 if ([response count]>0) { NSArray *array = [response valueForKey:@"response"]; for (int i=0; i<[array count]; i++) { [arrayLat addObject:[[[r
markerinfowindow
,并显示一些信息,如名称和编号
if ([response count]>0)
{
NSArray *array = [response valueForKey:@"response"];
for (int i=0; i<[array count]; i++)
{
[arrayLat addObject:[[[response valueForKey:@"response"] objectAtIndex:i] valueForKey:@"lat"]];
[arrLong addObject:[[[response valueForKey:@"response"] objectAtIndex:i] valueForKey:@"longi"]];
position = CLLocationCoordinate2DMake([[arrayLat objectAtIndex:i]floatValue],[[arrLong objectAtIndex:i]floatValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
//marker.title = [titlearr objectAtIndex:i];
// marker.snippet = @"Subtitle";
marker.flat=YES;
marker.map = mapView;
mapView.delegate = self;
//marker.title=[[[response valueForKey:@"response"] objectAtIndex:i] valueForKey:@"firstname"];
marker.icon = [GMSMarker markerImageWithColor:[UIColor redColor]];
mapView.delegate = self;
}
}
您可以使用GMSMarker的属性userData 示例:您有如下数据
json = [{"id":1,"name":"demo", "city":"BOTAD"},{"id":2,"name":"demo2", "city":"SURAT"}]
如果您想显示BOTAD的数据,那么将userData设置为
GMSMarker *marker = [[GMSMarker alloc] init];
marker.userData = [json objectAtIndex:0];
在这之后,您可以在委托方法下获得它,如
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
NSDictionary *data = marker.userData;
return mapView;
}
现在很容易从字典中获取城市和名称等数据,您可以在标签上设置文本
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
NSDictionary *data = marker.userData;
return mapView;
}