【问题标题】:GMSMarker not showing in 1.3GMSMarker 未在 1.3 中显示
【发布时间】:2013-05-18 03:14:15
【问题描述】:

我更新了我的应用以使用 Google Maps iOS SDK 1.3。除了 GMSMarkers 之外,一切似乎都有效。它们要么不出现,要么以错误的图像出现。它们仍然会响应触摸并且可以移动,但在其他方面是不可见或损坏的。

这里是添加 GMSMarkers 的代码:

playerAnnotation = [[CustomPlayerAnnotation markerWithPosition:coord] retain];
[playerAnnotation setType:ANNOTATION_PLAYER];
[playerAnnotation setIcon:[UIImage imageNamed:@"Icon-72.png"]];
[playerAnnotation setGroundAnchor:ccp(.5f, .5f)];
[playerAnnotation setAnimated:NO];
[playerAnnotation setTappable:YES];
[playerAnnotation setTitle:@"Player"];
[playerAnnotation setMap:gameMapView];

GMSMarker* test = [[GMSMarker markerWithPosition:gameMapView.myLocation.coordinate] retain];
[test setIcon:[UIImage imageNamed:@"Icon-72.png"]];
[test setGroundAnchor:ccp(.5f, .5f)];
[test setAnimated:NO];
[test setTappable:YES];
[test setTitle:@"Player"];
[test setMap:gameMapView];

CustomPlayerAnnotation 只是一个带有一些额外变量的 GMSMarker:

@interface CustomPlayerAnnotation : GMSMarker
{
    AnnotationType type;
    int tag;
    struct CoordinatePair coordinatePair;
}

使用 CustomPlayerAnnotation 映射并测试 GMSMarker:

我确实有大量的地面叠加层,移除叠加层会使标记重新出现,但有些仍然有无法正确显示的奇怪图像。它在 1.2.2 中运行良好,但在 1.3 中运行良好。

有没有人有让标记工作的解决方法?其他人在 GMSMarkers 中看到了这种行为吗?

其他细节:应用使用cocos2d 2.0,加载地图前停止director,添加GMSMapView如下:

UIWindow* window = [(ProjectFusionAppDelegate*)[[UIApplication sharedApplication] delegate] window];
[[[window subviews] objectAtIndex:0] addSubview:gameMapView];

【问题讨论】:

  • Google Maps SDK for iOS 版本:1.3.0.3430 中的 GMSMarker 存在类似问题。我在它们之间用 GMSPolyline 绘制了点,所以我知道它们是,但没有出现标记。也使用 ARC。
  • 我尝试使用新的 1.3.1,但仍然缺少标记。

标签: ios google-maps-sdk-ios


【解决方案1】:

确保首先使用相机位置在视图中实例化地图对象,然后添加 GMSMarker。我正在创建我的标记,并将它们添加到地图中。什么都没有出现,颠倒了逻辑,一切都按预期显示。我的项目使用 ARC 仅供参考。

- (void)loadView {
  // Create a GMSCameraPosition that tells the map to display the
  // coordinates at zoom level 12.
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:43.071482
                                                        longitude:-70.749856
                                                             zoom:12];
  mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  mapView_.myLocationEnabled = YES;
  self.view = mapView_;

  // Creates a marker in the center of the map, make sure the mapView_ is created, and
  // has the camera position set.
  GMSMarker *marker = [[GMSMarker alloc] init];
  marker.position = CLLocationCoordinate2DMake(43.071482, -70.749856);
  marker.title = @"Portsmouth";
  marker.snippet = @"New Hampshire";
  marker.map = mapView_;

}

【讨论】:

  • 我先实例化地图对象,然后再实例化标记。不知道你说的颠倒逻辑是什么意思。您是说您创建了 GMSMarkers,然后创建了地图,然后添加了?我不这样做。
  • 我用相机位置在视图中创建了地图对象,将视图设置为地图对象,然后添加了 GMSMarkers。它们都按预期出现。在 1.3.0 上测试。
【解决方案2】:

Google 方面似乎存在错误。我刚刚停止使用我的 CustomPlayerAnnotation 或 GMSMarker,而是使用了 GMSGroundOverlay。那出现在地图上。然后我没有使用我在 CustomPlayerAnnotation 中内置的类型、标签和坐标对,而是依赖标题。

playerAnnotation = [[GMSGroundOverlay groundOverlayWithPosition:coord icon:[UIImage imageNamed:@"Down1.png"]] retain];
[playerAnnotation setZoomLevel:zoomLevel];
[playerAnnotation setAnchor:ccp(.5f, 1)];
[playerAnnotation setTitle:@"Player"];
[playerAnnotation setMap:gameMapView];

旁注:请注意我必须 setAnchor:ccp(.5f, 1)。当它设置为 (.5f, .5f) 时,playerAnnotation 叠加层会在与其他 GMSGroundOverlays 重叠时切断叠加层的底部。更改锚点修复了 z 绘图。看起来刚刚发布的 1.4 可能已经修复了 z-ordering,但是 1.4 破坏了我的其他东西,所以我现在会坚持使用 1.3.1。

【讨论】:

    【解决方案3】:

    在设置Image之前设置边缘mapview

    var icon : UIImage = UIImage(named: "userLocation")!
                icon = icon.imageWithAlignmentRectInsets(UIEdgeInsetsMake(-(icon.size.height/2), -(icon.size.width/2), 0, 0))
                marker.icon = icon
                marker.map = GoogleMapView
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      相关资源
      最近更新 更多