每个纬度经度的标记信息窗口 google 地图 ios
markerinfowindow for every latitude longitude google map ios
我有经纬度和从 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;
}
}
我有数字、名称、纬度和经度的数组,简而言之,这里有所有信息
对于 markerinfowindow
,我正在使用此委托方法,现在我添加静态视图,但我想根据数组
动态显示 markerinfowindow
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
UIView *myview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 170, 80)];
myview.backgroundColor=[UIColor whiteColor];
UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(10,0, 150, 28)];
[lbl setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
lbl.text=@"3.Gregor cleasgance";
lbl.font = [UIFont boldSystemFontOfSize:13.0f];
lbl.textColor=[UIColor blackColor];
[myview addSubview:lbl];
UILabel *lbl2=[[UILabel alloc]initWithFrame:CGRectMake(10,24, 100, 20)];
[lbl2 setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
lbl2.text=@"Monday 07/02";
lbl2.textColor=[UIColor darkGrayColor];
[myview addSubview:lbl2];
UILabel *lbl3=[[UILabel alloc]initWithFrame:CGRectMake(120,24, 100, 20)];
[lbl3 setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
lbl3.text=@"14:00h";
lbl3.textColor=[UIColor darkGrayColor];
[myview addSubview:lbl3];
UILabel *lbl4=[[UILabel alloc]initWithFrame:CGRectMake(0,0, 7, 80)];
lbl4.backgroundColor=[UIColor colorWithRed:255.0/255.0 green:192.0/255.0 blue:1.0/255.0 alpha:1.0];
[myview addSubview:lbl4];
return myview;
}
您可以使用 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;
}
现在很容易从字典中获取城市和姓名等数据,您可以在标签上设置文本。
我有经纬度和从 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;
}
}
我有数字、名称、纬度和经度的数组,简而言之,这里有所有信息
对于 markerinfowindow
,我正在使用此委托方法,现在我添加静态视图,但我想根据数组
markerinfowindow
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
UIView *myview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 170, 80)];
myview.backgroundColor=[UIColor whiteColor];
UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(10,0, 150, 28)];
[lbl setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
lbl.text=@"3.Gregor cleasgance";
lbl.font = [UIFont boldSystemFontOfSize:13.0f];
lbl.textColor=[UIColor blackColor];
[myview addSubview:lbl];
UILabel *lbl2=[[UILabel alloc]initWithFrame:CGRectMake(10,24, 100, 20)];
[lbl2 setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
lbl2.text=@"Monday 07/02";
lbl2.textColor=[UIColor darkGrayColor];
[myview addSubview:lbl2];
UILabel *lbl3=[[UILabel alloc]initWithFrame:CGRectMake(120,24, 100, 20)];
[lbl3 setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
lbl3.text=@"14:00h";
lbl3.textColor=[UIColor darkGrayColor];
[myview addSubview:lbl3];
UILabel *lbl4=[[UILabel alloc]initWithFrame:CGRectMake(0,0, 7, 80)];
lbl4.backgroundColor=[UIColor colorWithRed:255.0/255.0 green:192.0/255.0 blue:1.0/255.0 alpha:1.0];
[myview addSubview:lbl4];
return myview;
}
您可以使用 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;
}
现在很容易从字典中获取城市和姓名等数据,您可以在标签上设置文本。