【问题标题】:iOS google maps sdk custom call out view and marker centeringiOS google maps sdk 自定义调出视图和标记居中
【发布时间】:2013-05-19 14:24:22
【问题描述】:

大家好,我现在正在使用 Google maps sdk,我有两个疑问:

标注:

如何自定义标注,我很难想出一种方法来自定义现有的东西,但我做不到。我找到了this

GMS 标记:

我想使标记在地图视图中居中,即标记应位于我设置的特定位置,并且还应保持当前缩放级别。

我做了标记居中,但现在我显示了来自标记的标注,我想将标注居中。

提前致谢。

【问题讨论】:

    标签: ios google-maps-sdk-ios


    【解决方案1】:

    对于 GMSMarker 问题:您必须创建一个指向标记位置的相机,然后将 mapview 相机设置为它

    somemarker = [[GMSMarker alloc] init];
    somemarker.position = CLLocationCoordinate2DMake(lat, lng);
    somemarker.map = mapView;
    
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:somemarker.position.latitude longitude:somemarker.position.longitude zoom:13];
    
    [mapView setCamera:camera];
    

    【讨论】:

      【解决方案2】:

      您可以查看我的 SO 回答 here,它显示了如何进行自定义信息窗口(标注)。

      【讨论】:

        【解决方案3】:

        您可以使用此代码来做到这一点 -

        - (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
        
        NSLog(@"the post title is :%@ %@",marker.userData,marker.title);
        
        CustomInfoWindow *view =  [[[NSBundle mainBundle] loadNibNamed:@"CustomInfoWindow" owner:self options:nil] objectAtIndex:0]; // Your Created Custom View XIB.
        
        UILabel *theLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 50,150, 50)];// Create a Custom Label and add it on the custom view.
        theLabel.text = marker.title; // marker.title is the title of pin.
        [view addSubview:theLabel];   
        return view;
        }
        

        【讨论】:

          猜你喜欢
          • 2017-03-05
          • 2014-05-15
          • 1970-01-01
          • 1970-01-01
          • 2019-11-14
          • 2014-05-20
          • 2016-02-08
          • 2017-04-10
          • 2021-10-22
          相关资源
          最近更新 更多