/ / Zobraziť zemepisnú šírku a dĺžku s viacerými údajmi JSON na mape v rýchlom 3? - json, swift3, mapkit

Zobraziť zemepisnú šírku a dĺžku s viacerými údajmi JSON na mape v rýchlom 3? - json, swift3, mapkit

Nie som schopný zobraziť viac údajov JSON szemepisnej šírky a zemepisnej dĺžky pomocou funkcie Alamofire v mapView.Normal Static Array sa zobrazí v aplikácii MapView, ale dynamické údaje sa v Mape nezobrazujú.Ako sa môže vyriešiť tento problém?

import UIKit
import MapKit
import Alamofire
import SwiftyJSON
class NearbyViewController: UIViewController,MKMapViewDelegate,CLLocationManagerDelegate {

@IBOutlet weak var mapview: MKMapView!
@IBOutlet weak var name: UILabel!

var schoolMap : [schools] = []
var scholmap : schools?

let locations = [
["title": "New York, NY",    "latitude": 40.713054, "longitude": -74.007228],
["title": "Los Angeles, CA", "latitude": 34.052238, "longitude": -118.243344],
["title": "Chicago, IL",     "latitude": 41.883229, "longitude": -87.632398]
]
override func viewDidLoad() {
super.viewDidLoad()
getschoolMapJson()
getmapSchool()


self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

}

override  func viewWillAppear(_ animated: Bool) {
mapview.reloadInputViews()
}
override func viewDidAppear(_ animated: Bool) {
mapview.reloadInputViews()
}

func getmapSchool(){

for locationn in schoolMap{
let location = CLLocationCoordinate2DMake((locationn.latitude) , (locationn.longitude))
print("lati",locationn.longitude)
let span = MKCoordinateSpanMake(10.0, 10.0)
let region = MKCoordinateRegionMake(location, span)
mapview.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = locationn.name
print("namelati",locationn.name)
mapview.addAnnotation(annotation)
}
}


func getschoolMapJson(){
if (schoolMap.count > 0){
return
}

let url = NSURL(string: "http://www.myeducationhunt.com/api/v1/schools")
var request = URLRequest(url: url! as URL)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
Alamofire.request(request).responseJSON(){ response in
switch response.result{
case.success(let data):
print("success api",data)
let myresponse = JSON(data)

/*for i in 0..<self.myresponse.count{
let schools_data = schools(schoolJson:self.myresponse[i])
self.schooldata.append(schools_data)

}*/
for school in myresponse.array!{
let schoolsObj = schools(schoolJson: school)
self.schoolMap.append(schoolsObj)
debugPrint(schoolsObj)
}
//                self.mapview.reloadInputViews()
case.failure(let error):
print("Not Success",error)
}

}
}
}

tu zadajte popis obrázku

Prečo nemôžem zobraziť dynamické údaje. Ako môže byť tento problém vyriešiť?

odpovede:

0 pre odpoveď č. 1

Nahraďte svoj kód nasledujúcim kódom:

for school in myresponse.array!{
let schoolsObj = schools(schoolJson: school)

//Add Pin
let location = CLLocationCoordinate2DMake((schoolsObj.latitude) , (schoolsObj.longitude))
let span = MKCoordinateSpanMake(10.0, 10.0)
let region = MKCoordinateRegionMake(location, span)
mapview.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = location
annotation.title = locationn.name
mapview.addAnnotation(annotation)

self.schoolMap.append(schoolsObj)

}

Releste to vo svojom getschoolMapJson()

Dúfam, že to bude fungovať