0

我有个问题。我为 ios 本机代码设置了谷歌地图 API。

我使用的是 Google Maps API 1.4.3 版。

我是自定义marker infoWindow中的一个mark成功。

但我无法设置关于多标记的不同 infoWindow 内容。

有没有人可以指导我,如何将不同的标题和片段传递给 markerInfoWindow 方法?或点击时如何知道标记?

我用一个标记和自定义 markerInfoWindow 部分攻击我的代码。

- (void)viewDidLoad
{
    [super viewDidLoad];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:25.03760471     longitude:121.5412 zoom:14];
    mapView = [GMSMapView mapWithFrame:CGRectMake(0, 0,     _mapBackgroundView.frame.size.width,_mapBackgroundView.frame.size.height) camera:camera];
    mapView.myLocationEnabled = YES;
    mapView.settings.myLocationButton = YES;
    mapView.settings.compassButton = YES;
    mapView.delegate = self;

    [self.mapBackgroundView addSubview:mapView];

    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(25.03760471, 121.5412);
    marker.map = mapView;

    GMSMarker *marker2 = [[GMSMarker alloc] init];
    marker2.position = CLLocationCoordinate2DMake(25.03760461, 121.5432);
    marker2.map = mapView;
}

-(UIView *) mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
    CustomInfoWindow *infoWindow = [[[NSBundle mainBundle]loadNibNamed:@"InfoWindow"   owner:self options:nil] objectAtIndex:0];
    infoWindow.titleLb.text = @"1th marks";
    infoWindow.snippetLb.text= @"1th marks snippet~";
    return infoWindow;
}

非常感谢~

4

1 回答 1

0

您可以通过多种方式做到这一点...通常您需要编写一个自定义类并在那里设置一些唯一的ID,以便稍后在委托方法中正确识别标记...但这是一种浪费的方式...

- (void)viewDidLoad
{
[super viewDidLoad];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:25.03760471     longitude:121.5412 zoom:14];
    mapView = [GMSMapView mapWithFrame:CGRectMake(0, 0,     _mapBackgroundView.frame.size.width,_mapBackgroundView.frame.size.height) camera:camera];
        mapView.myLocationEnabled = YES;
        mapView.settings.myLocationButton = YES;
        mapView.settings.compassButton = YES;
        mapView.delegate = self;

        [self.mapBackgroundView addSubview:mapView];

        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = CLLocationCoordinate2DMake(25.03760471, 121.5412);
        marker.map = mapView;
        marker.title= @"1st marker"; // set some title here

        GMSMarker *marker2 = [[GMSMarker alloc] init];
        marker2.position = CLLocationCoordinate2DMake(25.03760461, 121.5432);
        marker2.title= @"2nd marker";
        marker2.map = mapView;
}


-(UIView *) mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{

    CustomInfoWindow *infoWindow = [[[NSBundle mainBundle]loadNibNamed:@"InfoWindow"   owner:self options:nil] objectAtIndex:0];
    infoWindow.titleLb.text = marker.title;  // change the text according to the marker displayed here
    infoWindow.snippetLb.text= @"1th marks snippet~";


    return infoWindow;
}
于 2013-10-30T10:46:52.877 回答