【问题标题】:IOS google maps camera not point to the markerIOS谷歌地图相机不指向标记
【发布时间】:2014-06-05 11:18:15
【问题描述】:

我在故事板中有一个视图控制器,我想在上面显示谷歌地图

一切顺利,我拿到了,我可以显示地图了

我的问题是相机没有指向标记

这是我的代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"we are in the show stadium");
    // Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                            longitude:151.20
                                                                 zoom:6];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.myLocationEnabled = YES;
    self.mynewmap = mapView_;

    // Creates a marker in the center of the map.
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
    marker.title = @"Sydney";
    marker.snippet = @"Australia";
    marker.map = mapView_;
}

mynewmap是一个 UIView 出口

这是我看到的

标记在 austrail 但相机没有指向它并且标记不在地图上

【问题讨论】:

  • 我想知道你为什么投反对票?我有一个问题,我试图解决它,但我不能
  • 看看如果你注释掉'self.mynewmap = mapView_;'会发生什么设置 myLocation Enabled 应该会在地图的右下角显示一个图标。

标签: ios google-maps marker google-maps-sdk-ios


【解决方案1】:

如果您使用 Storyboard,请在 Interface Builder 中将 mynewmap 的类设置为 GMSMapView。

在 viewDidLoad 中只添加相机,不需要分配视图,因为它已经被分配了:

- (void)viewDidLoad
{
    [super viewDidLoad];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                        longitude:151.20
                                                             zoom:6];


    self.mynewmap.camera = camera;
}

或者尝试不使用零矩形创建您的视图.. CGRectZero...您可以尝试:

mapView_ = [GMSMapView mapWithFrame:self.mynewmap.frame camera:camera];

【讨论】:

    【解决方案2】:

    您当前的位置和 (-33.86,151.20) 位置是相同的,但不是...您已启用用户定位模式。请评论后再试

     //mapView_.myLocationEnabled = YES;
    

    删除这一行...因为它也在跟踪用户位置。可能会得到充分的帮助。

    【讨论】:

      【解决方案3】:

      完成添加标记后添加此行

      [mapView_ animateToLocation:marker.position];
      

      或使用

      [mapView_ animateToCameraPosition:[GMSCameraPosition cameraWithLatitude:marker.position.latitude
                                                                            longitude:marker.position.longitude
                                                                                 zoom:6.0f]];
      

      【讨论】:

        【解决方案4】:

        在 iOS 11 中面临同样的问题,而不是从情节提要中设置 GMSMapView,而是在 viewcontroller 的 viewDidLoad 方法中对其进行初始化,如下所示:

        override func viewDidLoad() {
            super.viewDidLoad()
        
            // Force the view to layout to get its proper frame
            self.view.setNeedsLayout()
            self.view.layoutIfNeeded()
            // Initialize the GMSMapView with target view's bounds
            googleMapView = GMSMapView(frame: self.mapView.bounds)
            // Add the GMSMapView to the map container view
            self.mapView.addSubview(googleMapView)
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-09-22
          • 2020-08-13
          • 2018-09-12
          • 1970-01-01
          • 1970-01-01
          • 2016-06-21
          • 1970-01-01
          相关资源
          最近更新 更多