【问题标题】:GMSMapView: center on coordinate and zoom out to reveal user locationGMSMapView:以坐标为中心并缩小以显示用户位置
【发布时间】:2014-07-21 17:50:29
【问题描述】:

我被困住了。 我希望有人能给我正确的意见!

我正在使用 GMSMapview 显示兴趣点 (GMSMarkers)。

目前我只是使用此代码将地图居中在当前 POI 坐标上(DEFAULT_ZOOM15.f):

GMSCameraPosition *newPosition =
             [GMSCameraPosition cameraWithLatitude:activePOI.coordinate.latitude
                                         longitude:activePOI.coordinate.longitude
                                              zoom:DEFAULT_ZOOM
                                           bearing:0.    //True north
                                      viewingAngle:0.];  //Facing down

[self.mapView animateToCameraPosition:newPosition];

我尝试使用 GMSCoordinateBounds 来显示 POI 和用户位置,代码如下:

GMSCoordinateBounds *cb =
             [[GMSCoordinateBounds alloc] initWithCoordinate:activePOI.coordinate 
             coordinate:user.coordinate];

[GMSCameraUpdate fitBounds:cb];

效果很好,但两个位置都显示在地图的角落。

我需要在中心显示兴趣点,但同时显示用户位置。

知道如何实现这一目标吗?

干杯。

【问题讨论】:

    标签: ios google-maps gmsmapview


    【解决方案1】:

    要在中心显示 POI,并在地图边缘显示用户位置,您应该派生第三个位置点,该位置点反映用户 llc 与 POI 另一侧的 POI 的相对距离。

    如果我们可以忽略地球的曲率,这就是简单的向量加法

    loc3 = poiLoc + (poiLoc - userLoc) 
         = 2*poiLoc - userLoc;
    

    那么你的地图矩形是由 userLoc 和 loc3 定义的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多