0

There isn't any clear answers that I could find so I wanted to give the answer that I came up with. Using an image from this URL

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

It gives the weather radar for the entire continental US. In order to place this image correctly on the map you need to know the coordinates of 2 points on the US that designate the bounds for the overlay. Using google maps here is the code for laying this over the map in Swift 3. You could easily edit this for mapkit as well.

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

This will overlay the latest doppler radar on top of the map. Now this doesn't take into consideration zooming and such so at certain zooms the image may be blurry nor does it remove any radar noise, certain blues. If you want to do that there is an excellent answer on SO here on replacing colors (hint: for transparent set the alpha to 0). If you replace a part of that answer with the following you'll remove the noise

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
        }
    }
}

Hope this helps.

Community
  • 1
  • 1
Micah Montoya
  • 757
  • 1
  • 8
  • 24
  • Does this actually display on the map accurately? I added this to mapkit and the image does not overlay onto the map that accurately. Try loading the image with the map and changing the alpha to 60% or something to see how accurately it overlays on the google maps iOS SDK. http://radar.weather.gov/Conus/RadarImg/latest.gif – Matt Dec 30 '16 at 08:58
  • I've not tried it with mapkit. Google map it lays correctly. You may need to adjust the coordinates a bit if it isn't positioning correctly. Latitude moves up and down and longitude moves left and right. So, play with them a bit to get the correct placement. – Micah Montoya Jan 02 '17 at 15:48
  • Mapkit is definitely not rendering it correctly. See my post here: http://stackoverflow.com/questions/41404670/mapkit-adding-raster-map-via-mkoverlay-weird-rendering-issue – Matt Jan 03 '17 at 06:14
  • I just built a test project and Google Maps iOS SDK definitely has the same issue. Try using the image with the base map and make it transparent: http://radar.weather.gov/ridge/Conus/RadarImg/latest.gif – Matt Jan 06 '17 at 21:49

0 Answers0