【问题标题】:How to set multi marks with custom infowindow at Google maps api for ios?如何在 Google maps api for ios 上使用自定义信息窗口设置多标记?
【发布时间】:2013-11-01 03:18:09
【问题描述】:

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

我使用的是 Google Maps API 1.4.3 版。

我是自定义标记infoWindow中的一个标记成功。

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

有没有人可以指导我,如何将不同的标题和 sn-p 传递给 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;
}

非常感谢~

【问题讨论】:

    标签: ios iphone google-maps infowindow


    【解决方案1】:

    您可以通过多种方式做到这一点...通常您需要编写一个自定义类并在那里设置一些唯一 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 2014-02-18
      • 1970-01-01
      • 2013-05-25
      相关资源
      最近更新 更多