Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
每个经纬度谷歌地图ios的markerinfowindow_Ios_Google Maps_Gmsmapview - Fatal编程技术网

每个经纬度谷歌地图ios的markerinfowindow

每个经纬度谷歌地图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

我有经纬度和从API获得的其他信息,但我想动态显示
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;
}