【问题标题】:Positioning camera that shows two places in GMSMapview iOS在 GMSMapview iOS 中显示两个位置的定位相机
【发布时间】:2017-04-26 10:28:51
【问题描述】:

我在我的 iOS 应用程序中使用 Google 地图服务 GMSMapview。我有两个 CLLocationCoordinates。一个是当前位置,另一个是目标位置。我正在尝试将地图放在这两个地方。

但相机位置并未设置在这两点内。我尝试使用以下代码,

CLLocationCoordinate2D start = CLLocationCoordinate2DMake(newLoc.coordinate.latitude, newLoc.coordinate.longitude);
CLLocationCoordinate2D end = CLLocationCoordinate2DMake(_retailerVO.R_Latitude, _retailerVO.R_Longitude);
GMSCoordinateBounds *gBounds =
[[GMSCoordinateBounds alloc] initWithCoordinate:start coordinate:end];
GMSCameraPosition *gCamera = [mapView_ cameraForBounds:gBounds insets:UIEdgeInsetsZero];
mapView_.camera = gCamera;

有什么方法可以实现我想要的吗?欢迎提出所有建议。

【问题讨论】:

    标签: ios gmsmapview


    【解决方案1】:

    在 Swift 中

     let bounds = GMSCoordinateBounds(coordinate: sourcePosition, coordinate: endPosition)
     let camera: GMSCameraUpdate = GMSCameraUpdate.fit(bounds)
     //  let cameraWithPadding: GMSCameraUpdate = GMSCameraUpdate.fit(bounds, withPadding: 100.0) (will put inset the bounding box from the view's edge)
    
     self.mapView.animate(with: camera)
    

    【讨论】:

      【解决方案2】:

      添加带边界的填充,它对我有用,希望对你有所帮助,

      GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:start coordinate:end];
      
      [self.viewMapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:100.0f]];
      

      【讨论】:

      • 如果您不介意,请告诉我,即使我们点击地图,有什么方法可以在地图上保留信息窗口(注释)吗?这意味着避免从地图中删除信息窗口。
      • 您可以根据自己的设计和要求设置GMSMarker的iconView
      • 只需根据您的设计创建一个视图并将其设置为标记的 iconView
      • 如果有人希望拟合两个以上的坐标,请使用 [bounds includeCoordinate: locationCoordinate] 来表示所有坐标
      • @PatelJigar 我已经创建了自定义标记的图标视图并将其添加到地图中,但有时标记视图被切入边缘。你能建议我可能的解决方案吗?地图有超过 2 个标记
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      相关资源
      最近更新 更多