我需要计算半径以根据相机缩放级别在 map 上显示标记。现在,我有southWestCorner,而我的位置是我的MapView的中心。缩放更改后,我需要缩小并计算新的半径。

有谁知道如何从我拥有的数据中获取数据?

我的代码在这里:

func mapView(mapView: GMSMapView!, idleAtCameraPosition position: GMSCameraPosition!) {

        println("latitude: \(position.target.latitude) longtitude: \(position.target.longitude)")

        var visibleRegion = mapView.projection.visibleRegion()
        var cameraZoom = mapView.camera.zoom
        var bounds = GMSCoordinateBounds(region: visibleRegion)
        var southWestCorner = bounds.southWest

    }

最佳答案

好的,我已经为我的问题找到了很好的答案。也许对其他人有帮助。根据这个article

要获取半径,请使用下一个示例(将所有函数转换为swift):

// calculate radius
    func getCenterCoordinate() -> CLLocationCoordinate2D {
        var centerPoint = self.mapView.center
        var centerCoordinate = self.mapView.projection.coordinateForPoint(centerPoint)
        return centerCoordinate
    }

    func getTopCenterCoordinate() -> CLLocationCoordinate2D {
        // to get coordinate from CGPoint of your map
        var topCenterCoor = self.mapView.convertPoint(CGPointMake(self.mapView.frame.size.width / 2.0, 0), fromView: self.mapView)
        var point = self.mapView.projection.coordinateForPoint(topCenterCoor)
        return point
    }

    func getRadius() -> CLLocationDistance {

        var centerCoordinate = getCenterCoordinate()
        // init center location from center coordinate
        var centerLocation = CLLocation(latitude: centerCoordinate.latitude, longitude: centerCoordinate.longitude)
        var topCenterCoordinate = self.getTopCenterCoordinate()
        var topCenterLocation = CLLocation(latitude: topCenterCoordinate.latitude, longitude: topCenterCoordinate.longitude)

        var radius = CLLocationDistance(centerLocation.distanceFromLocation(topCenterLocation))

        return round(radius)
    }

关于ios - Google Maps SDK iOS-根据缩放级别计算半径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31943778/

10-13 08:38