在谷歌地图上的Swift 3叠加多普勒雷达

时间:2016-12-14 14:35:10

标签: ios swift

我找不到任何明确的答案,所以我想给出我想出的答案。使用此网址中的图片

http://radar.weather.gov/ridge/Conus/RadarImg/latest_radaronly.gif

它为整个美国大陆提供了天气雷达。为了在地图上正确放置此图像,您需要知道美国2点的坐标,指定叠加的边界。在这里使用google maps是在Swift 3中将其放置在地图上的代码。您也可以轻松地为mapkit编辑它。

let southwestCoord = CLLocationCoordinate2DMake(21.652538062803, -127.620375523875420)
let northeastCoord = CLLocationCoordinate2DMake(50.406626367301044, -66.517937876818)
let overlayBounds = GMSCoordinateBounds(coordinate: southwestCoord, coordinate: northeastCoord)

let overlay = GMSGroundOverlay(bounds: overlayBounds, icon: image)
overlay.bearing = 0
overlay.map = self.mapView

这将覆盖地图顶部的最新多普勒雷达。现在,这并没有考虑到变焦等,在某些变焦处,图像可能会模糊,也不会消除任何雷达噪声,某些蓝光。如果你想这样做,关于替换颜色的SO here有一个很好的答案(提示:透明设置将alpha设置为0)。如果您使用以下内容替换该答案的一部分,则会删除噪音

let blue1 = RGBA32(red: 3, green: 0, blue: 244, alpha: 255)
let blue2 = RGBA32(red: 4, green: 233, blue: 231, alpha: 255)
let blue3 = RGBA32(red: 1, green: 159, blue: 244, alpha: 255)
let clear = RGBA32(red: 0, green: 0, blue: 0, alpha: 0)

for row in 0 ..< Int(height) {
    for column in 0 ..< Int(width) {
        let offset = row * width + column
        if pixelBuffer[offset] == blue1 {
            pixelBuffer[offset] = clear
        }

        if pixelBuffer[offset] == blue2 {
            pixelBuffer[offset] = clear
        }

        if pixelBuffer[offset] == blue3 {
            pixelBuffer[offset] = clear
        }
    }
}

希望这有帮助。

0 个答案:

没有答案