приложение загрузить широту и долготу с сервера на «moreViewController» У меня есть метка и когда я нажимаю контакт, как я могу преобразовать правильную широту или долготу (и изображение в другое представление) на эту метку?MKMapViewDelegate + JSON ALAMOFIRE
{
"latitude": 40.9233,
"longitude": 20.000,
"image" : "xxxx.xxx/xxx.jpg"
}
{
"latitude": 50.9233,
"longitude": 19.320,
"image" : "xxxx.xxx/yyy.jgp"
}
Так что я загрузить его и сохранить глобальный var test = [String:AnyObject]()
Alamofire.request("website").responseJSON { response in
print(response.result) // result of response serialization
let json = response.result.val
print("JSON: \(json)"
let jsonTab = json as? Array<Any>
for item in jsonTab as! [AnyObject] {
self.test["lat"] = item["lat"] as? Double! as AnyObject?
self.test["lng"] = item["lng"] as? Double! as AnyObject?
self.addPin(lat: self.test["lat"] as! Double, lng: self.test["lng"] as! Double)
и добавить штифт
func addPin(lat:Double, lng:Double) {
let testPin = CLLocationCoordinate2D(latitude: lat, longitude: lng)
let dropPin = MKPointAnnotation()
dropPin.coordinate = testPin
dropPin.title = "test"
mapView.addAnnotation(dropPin)
}
теперь добавить правую кнопку мыши и непосредственно перейти к следующему представлению
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
self.performSegue(withIdentifier: "more", sender: self)
}
var annotationIdentifier = ""
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var view = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
if view == nil {
view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
view?.canShowCallout = true
view?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
} else {
view?.annotation = annotation
}
return view
}
var selectedAnnotation: MKPointAnnotation!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.destination is moreViewController {
print("123")
let destViewController:moreViewController = segue.destination as! moreViewController
destViewController.lat = "\(latTest)"
}
}
Спасибо за работу отлично :)! – k0le
@ k0le Приветственный помощник :) –
извините, но у меня есть другой вопрос, который я не вижу, но это «место» имеет собственное имя как String и id как String на json, как я могу его переносить с помощью lat и long correct? – k0le