2015-03-03 57 views
0

我想在iOS Swift中統計用戶當前視圖中GMSCircles的數量。例如,當用戶放大或縮小時,我希望它計算屏幕上當前的圓圈數量。我有一些像現在這種權利要追加所有我的圈子畫面...計算查看Google Maps SDK中GMSCircles的數量...或者使用MarkerManager代替?這是否適用於iOS?

var circleCenter = CLLocationCoordinate2DMake(latitude, longitude); 
circle.append(GMSCircle(position: circleCenter, radius: 1)) 
circle[index].fillColor = UIColor(red: 0.35, green: 0, blue: 0, alpha: 0.05) 
circle[index].strokeColor = UIColor.redColor() 
circle[index].strokeWidth = 10 
circle[index].map = self.mapView; 

我在java中看到,有一個MarkerManager的標記(這是不同於圓圈我知道),在那裏你可以算在這樣的觀點的標記數:

count markers displayed on map after zoom in and out

,但我無法找到像MarkerManager斯威夫特對於什麼。有人能指引我朝着正確的方向發展嗎?我想用'圈子'......但是我認爲即使在java中也許很難做到。 iOS有像MarkerManager這樣的東西,可以用來計算標記而不是圈子嗎?任何幫助將非常棒,謝謝。

回答

0

這樣的事情就是我想要做的。使用名爲longitudeCollection而不是使用GMSCircles的類級別數組雖然

var visibleRegion : GMSVisibleRegion = mapView.projection.visibleRegion() 
    var bounds = GMSCoordinateBounds(coordinate: visibleRegion.nearLeft, coordinate: visibleRegion.farRight) 

    var numberOfCirclesInBounds = 0 

    for var index = 0; index<=longitudeCollection.count-1; index++ { 

     var foo = longitudeCollection[index].coordinateValue 
     var bar = latitudeCollection[index].coordinateValue 

     var circleCenter = CLLocationCoordinate2DMake(bar, foo); 

     if bounds.containsCoordinate(circleCenter) { 
      numberOfCirclesInBounds++ 
     } 
0

我不認爲有明確的方法,但你可以做的事情叫[cameraForBounds][1]獲得視口的邊界座標。有了這個,你可以檢查你的任何circleCenter是否落在視口範圍內。

+0

我不知道cameraForBounds存在,我會檢查出來,謝謝! – stepheaw 2015-03-03 18:35:51

相關問題