I have no idea where to begin.
Here's the documentation: https://openweathermap.org/api/weathermaps
Following that, and searching what I could online I tried the following, but it gives me a fatal error and never goes past that. (Note: I'm not sure what to put for the z, x, and y values either, so I left them, in addition to my API Key, blank here, but in my code I just put 1/1/1) My attempt, inserting temp_new to receive the temperature overlay:
Service.shared.getInfoCompletionHandler(requestURL: "https://tile.openweathermap.org/map/temp_new/{z}/{x}/{y}.png?appid={myKey}") { data in
if let data = data{
var geoJson = [MKGeoJSONObject]()
do{
geoJson = try MKGeoJSONDecoder().decode(data)
}
catch{
fatalError("Could not decode GeoJson")
}
var overlays = [MKOverlay]()
for item in geoJson{
if let feature = item as? MKGeoJSONFeature{
for geo in feature.geometry{
if let polygon = geo as? MKPolygon{
overlays.append(polygon)
}
}
}
}
DispatchQueue.main.async {
[unowned self] in
//set to global variable
self.overlays = overlays
}
}
}
My thought process was to simply extract the overlays and then add it to the MKMapView like this:
mapView.addOverlays(self.overlays)
If its relevant, this is the completion handler I have in my Service.swift for making the API call:
//Get Info API
func getInfoCompletionHandler(requestURL: String, completion: @escaping (Data?)->Void){
guard let url = URL(string: requestURL) else {return}
URLSession.shared.dataTask(with: url) { data, response, error in
if error == nil {
if let data = String(data: data!, encoding: .utf8), let response =
response{
print(data)
print(response)
}
} else{
if let error = error {
print(error)
}
}
completion(data)
}.resume()
Am I on the right track?
Any help is appreciated, thank you!
EDIT:
After playing around I noticed I can simply parse the data as imageData with the following code:
class ViewController: UIViewController {
//Properties
var imgData = Data()
let imageView = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
//imageView frame
view.addSubview(imageView)
imageView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.width)
imageView.center = view.center
imageView.contentMode = .scaleAspectFit
//image string
let imgString = "https://tile.openweathermap.org/map/temp_new/0/0/0.png?appid={myKey}"
//convert string to url object (needed to decode image data)
let imgUrl = URL(string: imgString)
//convert url to data
self.imgData = try! Data(contentsOf: imgUrl!)
//set to imageView
self.imageView.image = UIImage(data: self.imgData)
}
}
Giving me this result:
So now the only question that remains is how do I add this imageView as an overlay on the mapView?

Okay so I finally got it thanks to this tutorial:
https://www.raywenderlich.com/9956648-mapkit-tutorial-overlay-views#toc-anchor-003
I'll try to do my best to explain everything here the best I can, I copied a bunch of the code from Ray's website so I don't understand everything 100%. That being said, the main meat of what needs to be done is to layout the coordinates for the overlay. This was done in a custom class. The idea here is to parse coordinate data which was written in a plist in a Dictionary. For my project this was easy because I simply had to set the maximum coordinates for the Earth ((90, 180), (90, -180), (-90, -180), (-90, 180)). The mid coordinate only worked when I set it as (100, 0), not sure why, but the full code for parsing the plist is below.
After that I had to make it conform to NSObject (not very clear on this concept)
Then created a class that conforms to MKOverlayRenderer to give it instructions on how to draw the overlay.
Next I simply had to create a function which called the above classes:
Once that was done I just had to fill out the MKOverlayRenderer delegate as follows:
I hope this helps anyone who might come across this problem in the future. If anyone can further help explain these concepts as it is new to me, feel free!