0

我正在尝试将图像放置在 GMSGroundOverlay 中,但是当我缩小到缩放 < 3.0(世界级别)时发现了一些奇怪的东西。图像应覆盖 iPad 的整个屏幕,在缩放 >= 3.0 时效果很好。但是如果我缩小图像,则图像将放置在屏幕外,并且在您向左或向右平移时可见。

这就像它被包裹在地球上,但在反面。


  • 用户平移/缩放地图。
  • 当他们停下来时,我得到了 ipad 的屏幕尺寸,我调用了一个网络服务来让图像放置在整个屏幕上。
  • 它包含船舶位置和 Alpha 通道,因此您可以查看地图。

我在 iPad 上找到了地图的 4 个点。

                        //southWest = nearLeft
                    CLLocationCoordinate2D SW_ = CLLocationCoordinate2DMake([vesselTileRequest_.nearLeft_latitude doubleValue],
                                                                            [vesselTileRequest_.nearLeft_longitude doubleValue]);


                    //northEast = farRight = top right of ipad screen
                    CLLocationCoordinate2D NE_ = CLLocationCoordinate2DMake([vesselTileRequest_.farRight_latitude doubleValue],
                                                                            [vesselTileRequest_.farRight_longitude doubleValue]);
                    //-----------------------------------------------------------------------------------
                    CLLocationCoordinate2D SE_ = CLLocationCoordinate2DMake([vesselTileRequest_.nearRight_latitude doubleValue],
                                                                            [vesselTileRequest_.nearRight_longitude doubleValue]);


                    //northEast = farRight = top right of ipad screen
                    CLLocationCoordinate2D NW_ = CLLocationCoordinate2DMake([vesselTileRequest_.farLeft_latitude doubleValue],
                                                                            [vesselTileRequest_.farLeft_longitude doubleValue]);

我根据谷歌文档将图像放置在 SW,NE:

overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SW_
                                                     coordinate:NE_];
              self.overlay = [GMSGroundOverlay groundOverlayWithBounds:overlayBounds
                                                                            icon:responseImage_];

这适用于任何高于 3.0 的缩放级别。

但是当我们缩小时,地图上什么都不会出现,但是如果您向左或向右平移,图像已被映射到地球的另一侧。

当缩放小于 3.0 时,我不得不关闭重叠映射。

我尝试了 NW/NE/SW/SE 组合的所有组合,但所有对角都只是将图像放在地球的错误一侧。

if(self.mapView.camera.zoom < 3.0){
                        //nothing appears
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:NW_
//                                                                                 coordinate:NE_];

//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:NW_
//                                                                                 coordinate:SW_];
//
                        //appears but off screen
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:NW_
//                                                                                 coordinate:SE_];
//                          //nothing
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:NE_
//                                                                                 coordinate:NW_];
                        //off screen
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:NE_
//                                                                                 coordinate:SW_];
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:NE_
//                                                                                 coordinate:SE_];
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SW_
//                                                                                 coordinate:NW_];
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SW_
//                                                                                 coordinate:NE_];
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SW_
//                                                                                     coordinate:SW_];
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SW_
//                                                                                 coordinate:SE_];
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SE_
//                                                                                 coordinate:NW_];
//                            overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SE_
//                                                                                 coordinate:NE_];
                        overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SE_
                                                                             coordinate:SW_];
                        overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SE_
                                                                             coordinate:SW_];

                        self.overlay = [GMSGroundOverlay groundOverlayWithBounds:overlayBounds
                                                                            icon:responseImage_];

                        //-----------------------------------------------------------------------------------
////                            CLLocationCoordinate2D position_farLeft = CLLocationCoordinate2DMake(self.mapView.projection.visibleRegion.farLeft.latitude,
////                                                                                                 self.mapView.projection.visibleRegion.farLeft.longitude);
//                            CLLocationCoordinate2D position_farLeft = CLLocationCoordinate2DMake(0.0,
//                                                                                                 0.0);
//                            
//                            DebugLog(@"self.mapView.camera.zoom:%f",self.mapView.camera.zoom);
//                            self.overlay = [GMSGroundOverlay groundOverlayWithPosition:position_farLeft
//                                                                                  icon:responseImage_
//                                                                             zoomLevel:self.mapView.camera.zoom];
                        //-----------------------------------------------------------------------------------

                    }else{
                        //correct as of docs
                        overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:SW_
                                                                             coordinate:NE_];
                        self.overlay = [GMSGroundOverlay groundOverlayWithBounds:overlayBounds
                                                                            icon:responseImage_];
                    }

我还尝试了其他方法来创建叠加层,但如果我将位置硬编码为 0,0,那么在赤道上。它出现在澳大利亚上空。它又在地球的另一边,它应该在的地方

  CLLocationCoordinate2D position_farLeft = CLLocationCoordinate2DMake(self.mapView.projection.visibleRegion.farLeft.latitude,
                                                                   self.mapView.projection.visibleRegion.farLeft.longitude);
  CLLocationCoordinate2D position_farLeft = CLLocationCoordinate2DMake(0.0,
                                                                 0.0);
  DebugLog(@"self.mapView.camera.zoom:%f",self.mapView.camera.zoom);
  self.overlay = [GMSGroundOverlay groundOverlayWithPosition:position_farLeft
                                                  icon:responseImage_
                                             zoomLevel:self.mapView.camera.zoom];

结果 - 地图上什么也没有出现

结果 - 地图上什么也没有出现

如果我点击、按住并平移图像,则图像不在屏幕上。

如果我点击、按住并平移图像,则图像不在屏幕上。

如果我这样做并向右平移,您会看到图像正好在地球的另一侧,与 ipad 屏幕上显示的矩形正好相反

向左平移

4

2 回答 2

2

深入研究这一点,对于提出的第一个问题 - GMSGroundOverlay 在地球的背面,缩放级别为 3.0 或更低,罪魁祸首似乎是GMSCoordinateBounds initWithCoordinate:coordinate:初始化方法标准化坐标,根据方法文档:

/**
 * Inits the northEast and southWest bounds corresponding
 * to the rectangular region defined by the two corners.
 *
 * It is ambiguous whether the longitude of the box
 * extends from |coord1| to |coord2| or vice-versa;
 * the box is constructed as the smaller of the two variants, eliminating the
 * ambiguity.
 */

事实证明,对于处于横向模式的 iPad,缩放级别 3.0 是整个 GMSGroundOverlayvisibleRegion覆盖 180 度的点。缩小并GMSCoordinateBounds归一化到较小的区域,这恰好是地球的另一端。

这里真正的答案是使用GMSTileLayer

于 2015-01-27T05:58:59.053 回答
0

I faced with the same problem. Try not to use GMSCoordinateBounds. Use groundOverlayWithPosition:

    GMSGroundOverlay *overlay = [GMSGroundOverlay groundOverlayWithPosition:self.mapView.camera.target
                                                                       icon:image
                                                                  zoomLevel:self.mapView.camera.zoom];
    overlay.bearing = 0;
    overlay.map = self.mapView;
    overlay.zIndex = 2;
于 2015-04-21T20:52:49.670 回答