【问题标题】:Google Maps iOS: Move camera to show all markers present inside a clusterGoogle Maps iOS:移动相机以显示集群内的所有标记
【发布时间】:2019-10-19 18:09:22
【问题描述】:

当调用 didTap 集群函数时,它会将相机缩放到集群中存在的标记之一,但我想显示该集群中的所有标记并将相机聚焦在这些标记上。

我能够在 android 中实现这一点。但是在 iOS 中,google utils sdk 没有提供一种方法来获取集群对象中存在的所有项目。

这是安卓代码

mClusterManager
            .setOnClusterClickListener(new 
ClusterManager.OnClusterClickListener<Service_Provider>() {
                @Override
                public boolean onClusterClick(final Cluster<Service_Provider> cluster) {
        LatLngBounds.Builder builder = LatLngBounds.builder();
        for (ClusterItem item : cluster.getItems()) {
           builder.include(item.getPosition());
          Log.w(TAG, "Clicked Cluster Item name: " + item.getTitle());
         }
        final LatLngBounds bounds = builder.build();

        map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
                    return true;
                }
            });

到目前为止我在 iOS 中的尝试

func clusterManager(_ clusterManager: GMUClusterManager, didTap cluster: 
GMUCluster) -> Bool {
    print("Did tap cluster")
    let newCamera = GMSCameraPosition.camera(withTarget: cluster.position,
                                             zoom: mapView.camera.zoom +1)
    let update = GMSCameraUpdate.setCamera(newCamera)
    mapView.moveCamera(update)
}

感谢任何帮助。

TIA

【问题讨论】:

    标签: ios swift google-maps google-maps-ios-utils


    【解决方案1】:
    func showBoundBox( _ list : [CLLocationCoordinate2D]){
        
        var bounds = GMSCoordinateBounds()
        for location in list {
            bounds = bounds.includingCoordinate(location)
        }
            
        let update = GMSCameraUpdate.fit(bounds, withPadding: 100)
        map.animate(with: update)
        
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-17
      • 2020-11-07
      • 2018-01-03
      • 2013-03-07
      • 1970-01-01
      • 2020-07-01
      • 2011-08-25
      • 1970-01-01
      相关资源
      最近更新 更多